Skip to content

Commit b76cd74

Browse files
authored
opendrive: added --opendrive-access flag to handle permissions
1 parent 3b49fd2 commit b76cd74

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

backend/opendrive/opendrive.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ Note that these chunks are buffered in memory so increasing them will
9292
increase memory use.`,
9393
Default: 10 * fs.Mebi,
9494
Advanced: true,
95+
}, {
96+
Name: "access",
97+
Help: "Files and folders will be uploaded with this access permission (default private)",
98+
Default: "private",
99+
Advanced: true,
100+
Examples: []fs.OptionExample{{
101+
Value: "private",
102+
Help: "The file or folder access can be granted in a way that will allow select users to view, read or write what is absolutely essential for them.",
103+
}, {
104+
Value: "public",
105+
Help: "The file or folder can be downloaded by anyone from a web browser. The link can be shared in any way,",
106+
}, {
107+
Value: "hidden",
108+
Help: "The file or folder can be accessed has the same restrictions as Public if the user knows the URL of the file or folder link in order to access the contents",
109+
}},
95110
}},
96111
})
97112
}
@@ -102,6 +117,7 @@ type Options struct {
102117
Password string `config:"password"`
103118
Enc encoder.MultiEncoder `config:"encoding"`
104119
ChunkSize fs.SizeSuffix `config:"chunk_size"`
120+
Access string `config:"access"`
105121
}
106122

107123
// Fs represents a remote server
@@ -735,6 +751,23 @@ func (f *Fs) shouldRetry(ctx context.Context, resp *http.Response, err error) (b
735751
return fserrors.ShouldRetry(err) || fserrors.ShouldRetryHTTP(resp, retryErrorCodes), err
736752
}
737753

754+
// getAccessLevel is a helper function to determine access level integer
755+
func getAccessLevel(access string) int64 {
756+
var accessLevel int64
757+
switch access {
758+
case "private":
759+
accessLevel = 0
760+
case "public":
761+
accessLevel = 1
762+
case "hidden":
763+
accessLevel = 2
764+
default:
765+
accessLevel = 0
766+
fs.Errorf(nil, "Invalid access: %s, defaulting to private", access)
767+
}
768+
return accessLevel
769+
}
770+
738771
// DirCacher methods
739772

740773
// CreateDir makes a directory with pathID as parent and name leaf
@@ -747,7 +780,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
747780
SessionID: f.session.SessionID,
748781
FolderName: f.opt.Enc.FromStandardName(leaf),
749782
FolderSubParent: pathID,
750-
FolderIsPublic: 0,
783+
FolderIsPublic: getAccessLevel(f.opt.Access),
751784
FolderPublicUpl: 0,
752785
FolderPublicDisplay: 0,
753786
FolderPublicDnl: 0,
@@ -1080,7 +1113,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
10801113

10811114
// Set permissions
10821115
err = o.fs.pacer.Call(func() (bool, error) {
1083-
update := permissions{SessionID: o.fs.session.SessionID, FileID: o.id, FileIsPublic: 0}
1116+
update := permissions{SessionID: o.fs.session.SessionID, FileID: o.id, FileIsPublic: getAccessLevel(o.fs.opt.Access)}
10841117
// fs.Debugf(nil, "Permissions : %#v", update)
10851118
opts := rest.Opts{
10861119
Method: "POST",

0 commit comments

Comments
 (0)