feat(google_drive): add `hash_info`, `ctime`, `thumbnail` (#5334)

pull/5346/head
foxxorcat 2023-10-06 16:04:39 +08:00 committed by GitHub
parent a008f54f4d
commit 1a283bb272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -23,12 +24,17 @@ type File struct {
Name string `json:"name"` Name string `json:"name"`
MimeType string `json:"mimeType"` MimeType string `json:"mimeType"`
ModifiedTime time.Time `json:"modifiedTime"` ModifiedTime time.Time `json:"modifiedTime"`
CreatedTime time.Time `json:"createdTime"`
Size string `json:"size"` Size string `json:"size"`
ThumbnailLink string `json:"thumbnailLink"` ThumbnailLink string `json:"thumbnailLink"`
ShortcutDetails struct { ShortcutDetails struct {
TargetId string `json:"targetId"` TargetId string `json:"targetId"`
TargetMimeType string `json:"targetMimeType"` TargetMimeType string `json:"targetMimeType"`
} `json:"shortcutDetails"` } `json:"shortcutDetails"`
MD5Checksum string `json:"md5Checksum"`
SHA1Checksum string `json:"sha1Checksum"`
SHA256Checksum string `json:"sha256Checksum"`
} }
func fileToObj(f File) *model.ObjThumb { func fileToObj(f File) *model.ObjThumb {
@ -39,10 +45,18 @@ func fileToObj(f File) *model.ObjThumb {
ID: f.Id, ID: f.Id,
Name: f.Name, Name: f.Name,
Size: size, Size: size,
Ctime: f.CreatedTime,
Modified: f.ModifiedTime, Modified: f.ModifiedTime,
IsFolder: f.MimeType == "application/vnd.google-apps.folder", IsFolder: f.MimeType == "application/vnd.google-apps.folder",
HashInfo: utils.NewHashInfoByMap(map[*utils.HashType]string{
utils.MD5: f.MD5Checksum,
utils.SHA1: f.SHA1Checksum,
utils.SHA256: f.SHA256Checksum,
}),
},
Thumbnail: model.Thumbnail{
Thumbnail: f.ThumbnailLink,
}, },
Thumbnail: model.Thumbnail{},
} }
if f.MimeType == "application/vnd.google-apps.shortcut" { if f.MimeType == "application/vnd.google-apps.shortcut" {
obj.ID = f.ShortcutDetails.TargetId obj.ID = f.ShortcutDetails.TargetId

View File

@ -5,7 +5,6 @@ import (
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"github.com/alist-org/alist/v3/pkg/http_range"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
@ -13,6 +12,8 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/alist-org/alist/v3/pkg/http_range"
"github.com/alist-org/alist/v3/drivers/base" "github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
@ -195,7 +196,7 @@ func (d *GoogleDrive) getFiles(id string) ([]File, error) {
} }
query := map[string]string{ query := map[string]string{
"orderBy": orderBy, "orderBy": orderBy,
"fields": "files(id,name,mimeType,size,modifiedTime,thumbnailLink,shortcutDetails),nextPageToken", "fields": "files(id,name,mimeType,size,modifiedTime,createdTime,thumbnailLink,shortcutDetails,md5Checksum,sha1Checksum,sha256Checksum),nextPageToken",
"pageSize": "1000", "pageSize": "1000",
"q": fmt.Sprintf("'%s' in parents and trashed = false", id), "q": fmt.Sprintf("'%s' in parents and trashed = false", id),
//"includeItemsFromAllDrives": "true", //"includeItemsFromAllDrives": "true",

View File

@ -184,6 +184,10 @@ type HashInfo struct {
h map[*HashType]string `json:"hashInfo"` h map[*HashType]string `json:"hashInfo"`
} }
func NewHashInfoByMap(h map[*HashType]string) HashInfo {
return HashInfo{h}
}
func NewHashInfo(ht *HashType, str string) HashInfo { func NewHashInfo(ht *HashType, str string) HashInfo {
m := make(map[*HashType]string) m := make(map[*HashType]string)
if ht != nil { if ht != nil {