Skip to content

Commit f476e0f

Browse files
committed
cleanup
1 parent 58ded0c commit f476e0f

5 files changed

Lines changed: 9 additions & 130 deletions

File tree

backend/doi/api/dataversetypes.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ type DataverseDataset struct {
1515

1616
// DataverseDatasetVersion is the representation of a dataset version
1717
type DataverseDatasetVersion struct {
18-
LastUpdateTime string `json:"lastUpdateTime"`
19-
Files []DataverseFile `json:"files"`
20-
MetadataBlocks DataverseMetadataBlocks `json:"metadataBlocks"`
18+
LastUpdateTime string `json:"lastUpdateTime"`
19+
Files []DataverseFile `json:"files"`
2120
}
2221

2322
// DataverseFile is the representation of a file found in a dataset
@@ -37,19 +36,3 @@ type DataverseDataFile struct {
3736
OriginalFileName string `json:"originalFileName"`
3837
MD5 string `json:"md5"`
3938
}
40-
41-
// DataverseMetadataBlocks represents metadata of a Dataverse dataset
42-
type DataverseMetadataBlocks struct {
43-
Citation DataverseMetadataBlockCitation `json:"citation"`
44-
}
45-
46-
// DataverseMetadataBlockCitation represents citation metadata
47-
type DataverseMetadataBlockCitation struct {
48-
Fields []DataverseMetadataBlockCitationField `json:"fields"`
49-
}
50-
51-
// DataverseMetadataBlockCitationField a metadata field of citation metadata
52-
type DataverseMetadataBlockCitationField struct {
53-
TypeName string `json:"typeName"`
54-
Value any `json:"value"`
55-
}

backend/doi/api/inveniotypes.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ package api
44

55
// InvenioRecordResponse is the representation of a record stored in InvenioDRM
66
type InvenioRecordResponse struct {
7-
Links InvenioRecordResponseLinks `json:"links"`
8-
Metadata InvenioRecordMetadata `json:"metadata"`
7+
Links InvenioRecordResponseLinks `json:"links"`
8+
// Metadata InvenioRecordMetadata `json:"metadata"`
99
}
1010

1111
// InvenioRecordResponseLinks represents a record's links
1212
type InvenioRecordResponseLinks struct {
1313
Self string `json:"self"`
1414
}
1515

16-
// InvenioRecordMetadata respresents is the representation of a record's metadata
17-
type InvenioRecordMetadata struct {
18-
Title string `json:"title"`
19-
}
20-
2116
// InvenioFilesResponse is the representation of a record's files
2217
type InvenioFilesResponse struct {
2318
Entries []InvenioFilesResponseEntry `json:"entries"`

backend/doi/dataverse.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,3 @@ func (f *Fs) listDataverseDoiFiles(ctx context.Context) (entries []*Object, err
137137
f.cache.Put("files", cacheEntries)
138138
return entries, nil
139139
}
140-
141-
func (f *Fs) getMetadataDataverse(ctx context.Context) (metadata *api.DataverseDatasetResponse, err error) {
142-
metadataURL := f.endpoint
143-
var result api.DataverseDatasetResponse
144-
opts := rest.Opts{
145-
Method: "GET",
146-
RootURL: metadataURL.String(),
147-
}
148-
err = f.pacer.Call(func() (bool, error) {
149-
res, err := f.srv.CallJSON(ctx, &opts, nil, &result)
150-
return shouldRetry(ctx, res, err)
151-
})
152-
if err != nil {
153-
return nil, err
154-
}
155-
return &result, nil
156-
}

backend/doi/doi.go

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -511,32 +511,11 @@ func (o *Object) MimeType(ctx context.Context) string {
511511
var commandHelp = []fs.CommandHelp{{
512512
Name: "metadata",
513513
Short: "Show metadata about the DOI.",
514-
Long: `This command returns the JSON representation of the DOI.
514+
Long: `This command returns a JSON object with some information about the DOI.
515515
516516
rclone backend medatadata doi:
517517
518-
It returns a JSON object representing the DOI.
519-
`,
520-
}, {
521-
Name: "title",
522-
Short: "Show the DOI title if available.",
523-
Long: `This command returns the DOI title.
524-
525-
rclone backend title doi:
526-
527-
It returns a string representing the DOI title.
528-
`,
529-
}, {
530-
Name: "provider",
531-
Short: "Show the DOI provider.",
532-
Long: `This command returns the DOI provider.
533-
534-
rclone backend provider doi:
535-
536-
This command can be used to update the rclone.conf file for faster operations with the doi backend
537-
as auto-detection for the provider can be avoided.
538-
539-
It returns a string representing the DOI provider.
518+
It returns a JSON object representing metadata about the DOI.
540519
`,
541520
}, {
542521
Name: "set",
@@ -573,12 +552,6 @@ func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[str
573552
switch name {
574553
case "metadata":
575554
return f.ShowMetadata(ctx)
576-
case "title":
577-
return f.ShowTitle(ctx)
578-
case "provider":
579-
return string(f.provider), nil
580-
case "info":
581-
return f.ShowInfo(ctx)
582555
case "set":
583556
newOpt := f.opt
584557
err := configstruct.Set(configmap.Simple(opt), &newOpt)
@@ -601,54 +574,16 @@ func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[str
601574
}
602575
}
603576

604-
// ShowMetadata returns the metadata associated with the DOI
577+
// ShowMetadata returns some metadata about the corresponding DOI
605578
func (f *Fs) ShowMetadata(ctx context.Context) (metadata interface{}, err error) {
606-
metadataURL := f.endpoint
607-
var result any
608-
opts := rest.Opts{
609-
Method: "GET",
610-
RootURL: metadataURL.String(),
611-
}
612-
err = f.pacer.Call(func() (bool, error) {
613-
res, err := f.srv.CallJSON(ctx, &opts, nil, &result)
614-
return shouldRetry(ctx, res, err)
615-
})
579+
doiURL, err := url.Parse("https://doi.org/" + f.opt.Doi)
616580
if err != nil {
617581
return nil, err
618582
}
619-
return result, nil
620-
}
621-
622-
// ShowTitle returns the title associated with the DOI
623-
func (f *Fs) ShowTitle(ctx context.Context) (title string, err error) {
624-
switch f.provider {
625-
case Dataverse:
626-
metadata, err := f.getMetadataDataverse(ctx)
627-
if err != nil {
628-
return "", err
629-
}
630-
for _, field := range metadata.Data.LatestVersion.MetadataBlocks.Citation.Fields {
631-
if strings.ToLower(field.TypeName) == "title" {
632-
title, ok := field.Value.(string)
633-
if ok {
634-
return title, nil
635-
}
636-
}
637-
}
638-
case Invenio, Zenodo:
639-
metadata, err := f.getMetadataInvenio(ctx)
640-
if err != nil {
641-
return "", err
642-
}
643-
return metadata.Metadata.Title, nil
644-
645-
}
646-
return "<unknown title>", nil
647-
}
648583

649-
func (f *Fs) ShowInfo(ctx context.Context) (metadata interface{}, err error) {
650584
info := map[string]any{}
651585
info["DOI"] = f.opt.Doi
586+
info["URL"] = doiURL.String()
652587
info["metadataURL"] = f.endpointURL
653588
info["provider"] = f.provider
654589
return info, nil

backend/doi/invenio.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,3 @@ func (f *Fs) listInvevioDoiFiles(ctx context.Context) (entries []*Object, err er
167167
f.cache.Put("files", cacheEntries)
168168
return entries, nil
169169
}
170-
171-
func (f *Fs) getMetadataInvenio(ctx context.Context) (metadata *api.InvenioRecordResponse, err error) {
172-
metadataURL := f.endpoint
173-
var result api.InvenioRecordResponse
174-
opts := rest.Opts{
175-
Method: "GET",
176-
RootURL: metadataURL.String(),
177-
}
178-
err = f.pacer.Call(func() (bool, error) {
179-
res, err := f.srv.CallJSON(ctx, &opts, nil, &result)
180-
return shouldRetry(ctx, res, err)
181-
})
182-
if err != nil {
183-
return nil, err
184-
}
185-
return &result, nil
186-
}

0 commit comments

Comments
 (0)