Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
284035823f | |||
be8ff92414 | |||
a4c846a424 | |||
451e418b18 | |||
4e13b1a83c | |||
9d2e9887af |
13
.github/FUNDING.yml
vendored
Normal file
13
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||||
|
custom: ['https://alist.nn.ci/guide/sponsor.html']
|
@ -100,4 +100,4 @@ The `AList` is open-source software licensed under the AGPL-3.0 license.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
> [@Blog](https://nn.ci/) · [@GitHub](https://github.com/Xhofe) · [@TelegramGroup](https://t.me/alist_chat) · [@QQGroup](https://jq.qq.com/?_wv=1027&k=YJJj2Gwb)
|
> [@Blog](https://nn.ci/) · [@GitHub](https://github.com/Xhofe) · [@TelegramGroup](https://t.me/alist_chat) · [@Discord](https://discord.gg/F4ymsH4xv2)
|
@ -100,4 +100,4 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
> [@博客](https://nn.ci/) · [@GitHub](https://github.com/Xhofe) · [@Telegram群](https://t.me/alist_chat) · [@QQ群](https://jq.qq.com/?_wv=1027&k=YJJj2Gwb)
|
> [@博客](https://nn.ci/) · [@GitHub](https://github.com/Xhofe) · [@Telegram群](https://t.me/alist_chat) · [@Discord](https://discord.gg/F4ymsH4xv2)
|
@ -11,6 +11,7 @@ import (
|
|||||||
_ "github.com/alist-org/alist/v3/drivers/baidu_photo"
|
_ "github.com/alist-org/alist/v3/drivers/baidu_photo"
|
||||||
_ "github.com/alist-org/alist/v3/drivers/ftp"
|
_ "github.com/alist-org/alist/v3/drivers/ftp"
|
||||||
_ "github.com/alist-org/alist/v3/drivers/google_drive"
|
_ "github.com/alist-org/alist/v3/drivers/google_drive"
|
||||||
|
_ "github.com/alist-org/alist/v3/drivers/google_photo"
|
||||||
_ "github.com/alist-org/alist/v3/drivers/lanzou"
|
_ "github.com/alist-org/alist/v3/drivers/lanzou"
|
||||||
_ "github.com/alist-org/alist/v3/drivers/local"
|
_ "github.com/alist-org/alist/v3/drivers/local"
|
||||||
_ "github.com/alist-org/alist/v3/drivers/mediatrack"
|
_ "github.com/alist-org/alist/v3/drivers/mediatrack"
|
||||||
|
170
drivers/google_photo/driver.go
Normal file
170
drivers/google_photo/driver.go
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
package google_photo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GooglePhoto struct {
|
||||||
|
model.Storage
|
||||||
|
Addition
|
||||||
|
AccessToken string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Config() driver.Config {
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) GetAddition() driver.Additional {
|
||||||
|
return d.Addition
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Init(ctx context.Context, storage model.Storage) error {
|
||||||
|
d.Storage = storage
|
||||||
|
err := utils.Json.UnmarshalFromString(d.Storage.Addition, &d.Addition)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d.refreshToken()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Drop(ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
|
||||||
|
files, err := d.getFiles()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return utils.SliceConvert(files, func(src MediaItem) (model.Obj, error) {
|
||||||
|
return fileToObj(src), nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//func (d *GooglePhoto) Get(ctx context.Context, path string) (model.Obj, error) {
|
||||||
|
// // this is optional
|
||||||
|
// return nil, errs.NotImplement
|
||||||
|
//}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
||||||
|
f, err := d.getFile(file.GetID())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(f.MimeType, "image/") {
|
||||||
|
return &model.Link{
|
||||||
|
URL: f.BaseURL + "=d",
|
||||||
|
}, nil
|
||||||
|
} else if strings.Contains(f.MimeType, "video/") {
|
||||||
|
return &model.Link{
|
||||||
|
URL: f.BaseURL + "=dv",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
return &model.Link{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
|
||||||
|
return errs.NotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
|
||||||
|
return errs.NotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
|
||||||
|
return errs.NotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
|
||||||
|
return errs.NotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Remove(ctx context.Context, obj model.Obj) error {
|
||||||
|
return errs.NotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
|
||||||
|
var e Error
|
||||||
|
// Create resumable upload url
|
||||||
|
postHeaders := map[string]string{
|
||||||
|
"Authorization": "Bearer " + d.AccessToken,
|
||||||
|
"Content-type": "application/octet-stream",
|
||||||
|
"X-Goog-Upload-Command": "start",
|
||||||
|
"X-Goog-Upload-Content-Type": stream.GetMimetype(),
|
||||||
|
"X-Goog-Upload-Protocol": "resumable",
|
||||||
|
"X-Goog-Upload-Raw-Size": strconv.FormatInt(stream.GetSize(), 10),
|
||||||
|
}
|
||||||
|
url := "https://photoslibrary.googleapis.com/v1/uploads"
|
||||||
|
res, err := base.NoRedirectClient.R().SetHeaders(postHeaders).
|
||||||
|
SetError(&e).
|
||||||
|
Post(url)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if e.Error.Code != 0 {
|
||||||
|
if e.Error.Code == 401 {
|
||||||
|
err = d.refreshToken()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d.Put(ctx, dstDir, stream, up)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%s: %v", e.Error.Message, e.Error.Errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Upload to the Google Photo
|
||||||
|
postUrl := res.Header().Get("X-Goog-Upload-URL")
|
||||||
|
//chunkSize := res.Header().Get("X-Goog-Upload-Chunk-Granularity")
|
||||||
|
postHeaders = map[string]string{
|
||||||
|
"X-Goog-Upload-Command": "upload, finalize",
|
||||||
|
"X-Goog-Upload-Offset": "0",
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := d.request(postUrl, http.MethodPost, func(req *resty.Request) {
|
||||||
|
req.SetBody(stream.GetReadCloser())
|
||||||
|
}, nil, postHeaders)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
//Create MediaItem
|
||||||
|
createItemUrl := "https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate"
|
||||||
|
|
||||||
|
postHeaders = map[string]string{
|
||||||
|
"X-Goog-Upload-Command": "upload, finalize",
|
||||||
|
"X-Goog-Upload-Offset": "0",
|
||||||
|
}
|
||||||
|
|
||||||
|
data := base.Json{
|
||||||
|
"newMediaItems": []base.Json{
|
||||||
|
{
|
||||||
|
"description": "item-description",
|
||||||
|
"simpleMediaItem": base.Json{
|
||||||
|
"fileName": stream.GetName(),
|
||||||
|
"uploadToken": string(resp),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = d.request(createItemUrl, http.MethodPost, func(req *resty.Request) {
|
||||||
|
req.SetBody(data)
|
||||||
|
}, nil, postHeaders)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Driver = (*GooglePhoto)(nil)
|
29
drivers/google_photo/meta.go
Normal file
29
drivers/google_photo/meta.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package google_photo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Addition struct {
|
||||||
|
driver.RootID
|
||||||
|
RefreshToken string `json:"refresh_token" required:"true"`
|
||||||
|
ClientID string `json:"client_id" required:"true" default:"202264815644.apps.googleusercontent.com"`
|
||||||
|
ClientSecret string `json:"client_secret" required:"true" default:"X4Z3ca8xfWDb1Voo-F9a7ZxJ"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = driver.Config{
|
||||||
|
Name: "GooglePhoto",
|
||||||
|
OnlyProxy: true,
|
||||||
|
DefaultRoot: "root",
|
||||||
|
NoUpload: true,
|
||||||
|
LocalSort: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() driver.Driver {
|
||||||
|
return &GooglePhoto{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
op.RegisterDriver(config, New)
|
||||||
|
}
|
69
drivers/google_photo/types.go
Normal file
69
drivers/google_photo/types.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package google_photo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TokenError struct {
|
||||||
|
Error string `json:"error"`
|
||||||
|
ErrorDescription string `json:"error_description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Files struct {
|
||||||
|
NextPageToken string `json:"nextPageToken"`
|
||||||
|
MediaItems []MediaItem `json:"mediaItems"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaItem struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
BaseURL string `json:"baseUrl"`
|
||||||
|
MimeType string `json:"mimeType"`
|
||||||
|
FileName string `json:"filename"`
|
||||||
|
MediaMetadata MediaMetadata `json:"mediaMetadata"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaMetadata struct {
|
||||||
|
CreationTime time.Time `json:"creationTime"`
|
||||||
|
Width string `json:"width"`
|
||||||
|
Height string `json:"height"`
|
||||||
|
Photo Photo `json:"photo,omitempty"`
|
||||||
|
Video Video `json:"video,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Photo struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Video struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func fileToObj(f MediaItem) *model.ObjThumb {
|
||||||
|
//size, _ := strconv.ParseInt(f.Size, 10, 64)
|
||||||
|
return &model.ObjThumb{
|
||||||
|
Object: model.Object{
|
||||||
|
ID: f.Id,
|
||||||
|
Name: f.FileName,
|
||||||
|
Size: 0,
|
||||||
|
Modified: f.MediaMetadata.CreationTime,
|
||||||
|
IsFolder: false,
|
||||||
|
},
|
||||||
|
Thumbnail: model.Thumbnail{
|
||||||
|
Thumbnail: f.BaseURL + "=w100-h100-c",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Error struct {
|
||||||
|
Error struct {
|
||||||
|
Errors []struct {
|
||||||
|
Domain string `json:"domain"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
LocationType string `json:"location_type"`
|
||||||
|
Location string `json:"location"`
|
||||||
|
}
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
} `json:"error"`
|
||||||
|
}
|
105
drivers/google_photo/util.go
Normal file
105
drivers/google_photo/util.go
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
package google_photo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// do others that not defined in Driver interface
|
||||||
|
|
||||||
|
func (d *GooglePhoto) refreshToken() error {
|
||||||
|
url := "https://www.googleapis.com/oauth2/v4/token"
|
||||||
|
var resp base.TokenResp
|
||||||
|
var e TokenError
|
||||||
|
_, err := base.RestyClient.R().SetResult(&resp).SetError(&e).
|
||||||
|
SetFormData(map[string]string{
|
||||||
|
"client_id": d.ClientID,
|
||||||
|
"client_secret": d.ClientSecret,
|
||||||
|
"refresh_token": d.RefreshToken,
|
||||||
|
"grant_type": "refresh_token",
|
||||||
|
}).Post(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if e.Error != "" {
|
||||||
|
return fmt.Errorf(e.Error)
|
||||||
|
}
|
||||||
|
d.AccessToken = resp.AccessToken
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) request(url string, method string, callback base.ReqCallback, resp interface{}, headers map[string]string) ([]byte, error) {
|
||||||
|
req := base.RestyClient.R()
|
||||||
|
req.SetHeader("Authorization", "Bearer "+d.AccessToken)
|
||||||
|
if headers != nil {
|
||||||
|
req.SetHeaders(headers)
|
||||||
|
}
|
||||||
|
|
||||||
|
if callback != nil {
|
||||||
|
callback(req)
|
||||||
|
}
|
||||||
|
if resp != nil {
|
||||||
|
req.SetResult(resp)
|
||||||
|
}
|
||||||
|
var e Error
|
||||||
|
req.SetError(&e)
|
||||||
|
res, err := req.Execute(method, url)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if e.Error.Code != 0 {
|
||||||
|
if e.Error.Code == 401 {
|
||||||
|
err = d.refreshToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return d.request(url, method, callback, resp, headers)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("%s: %v", e.Error.Message, e.Error.Errors)
|
||||||
|
}
|
||||||
|
return res.Body(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) getFiles() ([]MediaItem, error) {
|
||||||
|
pageToken := "first"
|
||||||
|
res := make([]MediaItem, 0)
|
||||||
|
for pageToken != "" {
|
||||||
|
if pageToken == "first" {
|
||||||
|
pageToken = ""
|
||||||
|
}
|
||||||
|
var resp Files
|
||||||
|
query := map[string]string{
|
||||||
|
"fields": "mediaItems(id,baseUrl,mimeType,mediaMetadata,filename),nextPageToken",
|
||||||
|
"pageSize": "100",
|
||||||
|
"pageToken": pageToken,
|
||||||
|
}
|
||||||
|
_, err := d.request("https://photoslibrary.googleapis.com/v1/mediaItems", http.MethodGet, func(req *resty.Request) {
|
||||||
|
req.SetQueryParams(query)
|
||||||
|
}, &resp, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pageToken = resp.NextPageToken
|
||||||
|
res = append(res, resp.MediaItems...)
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *GooglePhoto) getFile(id string) (MediaItem, error) {
|
||||||
|
var resp MediaItem
|
||||||
|
|
||||||
|
query := map[string]string{
|
||||||
|
"fields": "baseUrl,mimeType",
|
||||||
|
}
|
||||||
|
_, err := d.request(fmt.Sprintf("https://photoslibrary.googleapis.com/v1/mediaItems/%s", id), http.MethodGet, func(req *resty.Request) {
|
||||||
|
req.SetQueryParams(query)
|
||||||
|
}, &resp, nil)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
driver.RootPath
|
driver.RootPath
|
||||||
Region string `json:"region" type:"select" required:"true" options:"global,cn,us,de"`
|
Region string `json:"region" type:"select" required:"true" options:"global,cn,us,de" default:"global"`
|
||||||
IsSharepoint bool `json:"is_sharepoint"`
|
IsSharepoint bool `json:"is_sharepoint"`
|
||||||
ClientID string `json:"client_id" required:"true"`
|
ClientID string `json:"client_id" required:"true"`
|
||||||
ClientSecret string `json:"client_secret" required:"true"`
|
ClientSecret string `json:"client_secret" required:"true"`
|
||||||
|
@ -166,7 +166,7 @@ func (d *Onedrive) upBig(ctx context.Context, dstDir model.Obj, stream model.Fil
|
|||||||
}
|
}
|
||||||
uploadUrl := jsoniter.Get(res, "uploadUrl").ToString()
|
uploadUrl := jsoniter.Get(res, "uploadUrl").ToString()
|
||||||
var finish int64 = 0
|
var finish int64 = 0
|
||||||
const DEFAULT = 4 * 1024 * 1024
|
const DEFAULT = 100 * 1024 * 1024
|
||||||
for finish < stream.GetSize() {
|
for finish < stream.GetSize() {
|
||||||
if utils.IsCanceled(ctx) {
|
if utils.IsCanceled(ctx) {
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
@ -38,6 +38,13 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li
|
|||||||
}
|
}
|
||||||
path = utils.StandardizePath(path)
|
path = utils.StandardizePath(path)
|
||||||
log.Debugf("op.List %s", path)
|
log.Debugf("op.List %s", path)
|
||||||
|
key := Key(storage, path)
|
||||||
|
if len(refresh) == 0 || !refresh[0] {
|
||||||
|
if files, ok := listCache.Get(key); ok {
|
||||||
|
log.Debugf("use cache when list %s", path)
|
||||||
|
return files, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
dir, err := Get(ctx, storage, path)
|
dir, err := Get(ctx, storage, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "failed get dir")
|
return nil, errors.WithMessage(err, "failed get dir")
|
||||||
@ -46,22 +53,14 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li
|
|||||||
if !dir.IsDir() {
|
if !dir.IsDir() {
|
||||||
return nil, errors.WithStack(errs.NotFolder)
|
return nil, errors.WithStack(errs.NotFolder)
|
||||||
}
|
}
|
||||||
if storage.Config().NoCache {
|
|
||||||
objs, err := storage.List(ctx, dir, args)
|
|
||||||
return objs, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
key := Key(storage, path)
|
|
||||||
if len(refresh) == 0 || !refresh[0] {
|
|
||||||
if files, ok := listCache.Get(key); ok && len(files) > 0 {
|
|
||||||
return files, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
objs, err, _ := listG.Do(key, func() ([]model.Obj, error) {
|
objs, err, _ := listG.Do(key, func() ([]model.Obj, error) {
|
||||||
files, err := storage.List(ctx, dir, args)
|
files, err := storage.List(ctx, dir, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to list objs")
|
return nil, errors.Wrapf(err, "failed to list objs")
|
||||||
}
|
}
|
||||||
|
if !storage.Config().NoCache && len(files) > 0 {
|
||||||
listCache.Set(key, files, cache.WithEx[[]model.Obj](time.Minute*time.Duration(storage.GetStorage().CacheExpiration)))
|
listCache.Set(key, files, cache.WithEx[[]model.Obj](time.Minute*time.Duration(storage.GetStorage().CacheExpiration)))
|
||||||
|
}
|
||||||
return files, nil
|
return files, nil
|
||||||
})
|
})
|
||||||
return objs, err
|
return objs, err
|
||||||
@ -128,6 +127,7 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Debugf("cant find obj with name: %s", name)
|
||||||
return nil, errors.WithStack(errs.ObjectNotFound)
|
return nil, errors.WithStack(errs.ObjectNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user