@@ -10,6 +10,7 @@ import (
1010 "time"
1111
1212 "github.com/OpenListTeam/OpenList/v4/internal/driver"
13+ "github.com/OpenListTeam/OpenList/v4/internal/errs"
1314 "github.com/OpenListTeam/OpenList/v4/internal/model"
1415 "github.com/OpenListTeam/OpenList/v4/internal/stream"
1516 "github.com/OpenListTeam/OpenList/v4/pkg/cron"
@@ -24,9 +25,10 @@ import (
2425type S3 struct {
2526 model.Storage
2627 Addition
27- Session * session.Session
28- client * s3.S3
29- linkClient * s3.S3
28+ Session * session.Session
29+ client * s3.S3
30+ linkClient * s3.S3
31+ directUploadClient * s3.S3
3032
3133 config driver.Config
3234 cron * cron.Cron
@@ -52,16 +54,18 @@ func (d *S3) Init(ctx context.Context) error {
5254 if err != nil {
5355 log .Errorln ("Doge init session error:" , err )
5456 }
55- d .client = d .getClient (false )
56- d .linkClient = d .getClient (true )
57+ d .client = d .getClient (ClientTypeNormal )
58+ d .linkClient = d .getClient (ClientTypeLink )
59+ d .directUploadClient = d .getClient (ClientTypeDirectUpload )
5760 })
5861 }
5962 err := d .initSession ()
6063 if err != nil {
6164 return err
6265 }
63- d .client = d .getClient (false )
64- d .linkClient = d .getClient (true )
66+ d .client = d .getClient (ClientTypeNormal )
67+ d .linkClient = d .getClient (ClientTypeLink )
68+ d .directUploadClient = d .getClient (ClientTypeDirectUpload )
6569 return nil
6670}
6771
@@ -210,4 +214,33 @@ func (d *S3) Put(ctx context.Context, dstDir model.Obj, s model.FileStreamer, up
210214 return err
211215}
212216
217+ func (d * S3 ) GetDirectUploadTools () []string {
218+ if ! d .EnableDirectUpload {
219+ return nil
220+ }
221+ return []string {"HttpDirect" }
222+ }
223+
224+ func (d * S3 ) GetDirectUploadInfo (ctx context.Context , _ string , dstDir model.Obj , fileName string , _ int64 ) (any , error ) {
225+ if ! d .EnableDirectUpload {
226+ return nil , errs .NotImplement
227+ }
228+ path := getKey (stdpath .Join (dstDir .GetPath (), fileName ), false )
229+ req , _ := d .directUploadClient .PutObjectRequest (& s3.PutObjectInput {
230+ Bucket : & d .Bucket ,
231+ Key : & path ,
232+ })
233+ if req == nil {
234+ return nil , fmt .Errorf ("failed to create PutObject request" )
235+ }
236+ link , err := req .Presign (time .Hour * time .Duration (d .SignURLExpire ))
237+ if err != nil {
238+ return nil , err
239+ }
240+ return & model.HttpDirectUploadInfo {
241+ UploadURL : link ,
242+ Method : "PUT" ,
243+ }, nil
244+ }
245+
213246var _ driver.Driver = (* S3 )(nil )
0 commit comments