Feat: use RFC3339 time format in returned results (#811)
This commit is contained in:
parent
a1252c810b
commit
96712fb066
6 changed files with 46 additions and 40 deletions
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 522a75c750ab78496e160b481a286013df4e0914
|
Subproject commit 08a301d53a39d0a67a2714caef9866c1eeaa4ee3
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
model "github.com/cloudreve/Cloudreve/v3/models"
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/fsctx"
|
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/fsctx"
|
||||||
|
@ -20,14 +21,14 @@ import (
|
||||||
|
|
||||||
// Object 文件或者目录
|
// Object 文件或者目录
|
||||||
type Object struct {
|
type Object struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Pic string `json:"pic"`
|
Pic string `json:"pic"`
|
||||||
Size uint64 `json:"size"`
|
Size uint64 `json:"size"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Date string `json:"date"`
|
Date time.Time `json:"date"`
|
||||||
Key string `json:"key,omitempty"`
|
Key string `json:"key,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename 重命名对象
|
// Rename 重命名对象
|
||||||
|
@ -349,7 +350,7 @@ func (fs *FileSystem) listObjects(ctx context.Context, parent string, files []mo
|
||||||
Pic: "",
|
Pic: "",
|
||||||
Size: 0,
|
Size: 0,
|
||||||
Type: "dir",
|
Type: "dir",
|
||||||
Date: subFolder.CreatedAt.Format("2006-01-02 15:04:05"),
|
Date: subFolder.CreatedAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +370,7 @@ func (fs *FileSystem) listObjects(ctx context.Context, parent string, files []mo
|
||||||
Pic: file.PicInfo,
|
Pic: file.PicInfo,
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
Type: "file",
|
Type: "file",
|
||||||
Date: file.CreatedAt.Format("2006-01-02 15:04:05"),
|
Date: file.CreatedAt,
|
||||||
}
|
}
|
||||||
if shareKey != "" {
|
if shareKey != "" {
|
||||||
newFile.Key = shareKey
|
newFile.Key = shareKey
|
||||||
|
|
|
@ -2,6 +2,7 @@ package serializer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
|
|
||||||
model "github.com/cloudreve/Cloudreve/v3/models"
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/aria2/rpc"
|
"github.com/cloudreve/Cloudreve/v3/pkg/aria2/rpc"
|
||||||
|
@ -9,7 +10,7 @@ import (
|
||||||
|
|
||||||
// DownloadListResponse 下载列表响应条目
|
// DownloadListResponse 下载列表响应条目
|
||||||
type DownloadListResponse struct {
|
type DownloadListResponse struct {
|
||||||
UpdateTime int64 `json:"update"`
|
UpdateTime time.Time `json:"update"`
|
||||||
UpdateInterval int `json:"interval"`
|
UpdateInterval int `json:"interval"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
|
@ -31,8 +32,8 @@ type FinishedListResponse struct {
|
||||||
Files []rpc.FileInfo `json:"files"`
|
Files []rpc.FileInfo `json:"files"`
|
||||||
TaskStatus int `json:"task_status"`
|
TaskStatus int `json:"task_status"`
|
||||||
TaskError string `json:"task_error"`
|
TaskError string `json:"task_error"`
|
||||||
CreateTime string `json:"create"`
|
CreateTime time.Time `json:"create"`
|
||||||
UpdateTime string `json:"update"`
|
UpdateTime time.Time `json:"update"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildFinishedListResponse 构建已完成任务条目
|
// BuildFinishedListResponse 构建已完成任务条目
|
||||||
|
@ -59,8 +60,8 @@ func BuildFinishedListResponse(tasks []model.Download) Response {
|
||||||
Total: tasks[i].TotalSize,
|
Total: tasks[i].TotalSize,
|
||||||
Files: tasks[i].StatusInfo.Files,
|
Files: tasks[i].StatusInfo.Files,
|
||||||
TaskStatus: -1,
|
TaskStatus: -1,
|
||||||
UpdateTime: tasks[i].UpdatedAt.Format("2006-01-02 15:04:05"),
|
UpdateTime: tasks[i].UpdatedAt,
|
||||||
CreateTime: tasks[i].CreatedAt.Format("2006-01-02 15:04:05"),
|
CreateTime: tasks[i].CreatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
if tasks[i].Task != nil {
|
if tasks[i].Task != nil {
|
||||||
|
@ -92,7 +93,7 @@ func BuildDownloadingResponse(tasks []model.Download) Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = append(resp, DownloadListResponse{
|
resp = append(resp, DownloadListResponse{
|
||||||
UpdateTime: tasks[i].UpdatedAt.Unix(),
|
UpdateTime: tasks[i].UpdatedAt,
|
||||||
UpdateInterval: interval,
|
UpdateInterval: interval,
|
||||||
Name: fileName,
|
Name: fileName,
|
||||||
Status: tasks[i].Status,
|
Status: tasks[i].Status,
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package serializer
|
package serializer
|
||||||
|
|
||||||
import model "github.com/cloudreve/Cloudreve/v3/models"
|
import (
|
||||||
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// SiteConfig 站点全局设置序列
|
// SiteConfig 站点全局设置序列
|
||||||
type SiteConfig struct {
|
type SiteConfig struct {
|
||||||
|
@ -22,11 +25,11 @@ type SiteConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type task struct {
|
type task struct {
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
CreateDate string `json:"create_date"`
|
CreateDate time.Time `json:"create_date"`
|
||||||
Progress int `json:"progress"`
|
Progress int `json:"progress"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildTaskList 构建任务列表响应
|
// BuildTaskList 构建任务列表响应
|
||||||
|
@ -36,7 +39,7 @@ func BuildTaskList(tasks []model.Task, total int) Response {
|
||||||
res = append(res, task{
|
res = append(res, task{
|
||||||
Status: t.Status,
|
Status: t.Status,
|
||||||
Type: t.Type,
|
Type: t.Type,
|
||||||
CreateDate: t.CreatedAt.Format("2006-01-02 15:04:05"),
|
CreateDate: t.CreatedAt,
|
||||||
Progress: t.Progress,
|
Progress: t.Progress,
|
||||||
Error: t.Error,
|
Error: t.Error,
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,7 +12,7 @@ type Share struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Locked bool `json:"locked"`
|
Locked bool `json:"locked"`
|
||||||
IsDir bool `json:"is_dir"`
|
IsDir bool `json:"is_dir"`
|
||||||
CreateDate string `json:"create_date,omitempty"`
|
CreateDate time.Time `json:"create_date,omitempty"`
|
||||||
Downloads int `json:"downloads"`
|
Downloads int `json:"downloads"`
|
||||||
Views int `json:"views"`
|
Views int `json:"views"`
|
||||||
Expire int64 `json:"expire"`
|
Expire int64 `json:"expire"`
|
||||||
|
@ -37,7 +37,7 @@ type myShareItem struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
IsDir bool `json:"is_dir"`
|
IsDir bool `json:"is_dir"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
CreateDate string `json:"create_date,omitempty"`
|
CreateDate time.Time `json:"create_date,omitempty"`
|
||||||
Downloads int `json:"downloads"`
|
Downloads int `json:"downloads"`
|
||||||
RemainDownloads int `json:"remain_downloads"`
|
RemainDownloads int `json:"remain_downloads"`
|
||||||
Views int `json:"views"`
|
Views int `json:"views"`
|
||||||
|
@ -55,7 +55,7 @@ func BuildShareList(shares []model.Share, total int) Response {
|
||||||
Key: hashid.HashID(shares[i].ID, hashid.ShareID),
|
Key: hashid.HashID(shares[i].ID, hashid.ShareID),
|
||||||
IsDir: shares[i].IsDir,
|
IsDir: shares[i].IsDir,
|
||||||
Password: shares[i].Password,
|
Password: shares[i].Password,
|
||||||
CreateDate: shares[i].CreatedAt.Format("2006-01-02 15:04:05"),
|
CreateDate: shares[i].CreatedAt,
|
||||||
Downloads: shares[i].Downloads,
|
Downloads: shares[i].Downloads,
|
||||||
Views: shares[i].Views,
|
Views: shares[i].Views,
|
||||||
Preview: shares[i].PreviewEnabled,
|
Preview: shares[i].PreviewEnabled,
|
||||||
|
@ -99,7 +99,7 @@ func BuildShareResponse(share *model.Share, unlocked bool) Share {
|
||||||
Nick: creator.Nick,
|
Nick: creator.Nick,
|
||||||
GroupName: creator.Group.Name,
|
GroupName: creator.Group.Name,
|
||||||
},
|
},
|
||||||
CreateDate: share.CreatedAt.Format("2006-01-02 15:04:05"),
|
CreateDate: share.CreatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 未解锁时只返回基本信息
|
// 未解锁时只返回基本信息
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
model "github.com/cloudreve/Cloudreve/v3/models"
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/hashid"
|
"github.com/cloudreve/Cloudreve/v3/pkg/hashid"
|
||||||
"github.com/duo-labs/webauthn/webauthn"
|
"github.com/duo-labs/webauthn/webauthn"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckLogin 检查登录
|
// CheckLogin 检查登录
|
||||||
|
@ -18,17 +19,17 @@ func CheckLogin() Response {
|
||||||
|
|
||||||
// User 用户序列化器
|
// User 用户序列化器
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Email string `json:"user_name"`
|
Email string `json:"user_name"`
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
PreferredTheme string `json:"preferred_theme"`
|
PreferredTheme string `json:"preferred_theme"`
|
||||||
Anonymous bool `json:"anonymous"`
|
Anonymous bool `json:"anonymous"`
|
||||||
Policy policy `json:"policy"`
|
Policy policy `json:"policy"`
|
||||||
Group group `json:"group"`
|
Group group `json:"group"`
|
||||||
Tags []tag `json:"tags"`
|
Tags []tag `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type policy struct {
|
type policy struct {
|
||||||
|
@ -94,7 +95,7 @@ func BuildUser(user model.User) User {
|
||||||
Nickname: user.Nick,
|
Nickname: user.Nick,
|
||||||
Status: user.Status,
|
Status: user.Status,
|
||||||
Avatar: user.Avatar,
|
Avatar: user.Avatar,
|
||||||
CreatedAt: user.CreatedAt.Unix(),
|
CreatedAt: user.CreatedAt,
|
||||||
PreferredTheme: user.OptionsSerialized.PreferredTheme,
|
PreferredTheme: user.OptionsSerialized.PreferredTheme,
|
||||||
Anonymous: user.IsAnonymous(),
|
Anonymous: user.IsAnonymous(),
|
||||||
Policy: policy{
|
Policy: policy{
|
||||||
|
|
Loading…
Add table
Reference in a new issue