mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-06-15 21:45:31 +00:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a6ff39e47d | ||
|
23eb739f01 | ||
|
ba285cb8bd | ||
|
63f01489a8 | ||
|
6bbb0802aa | ||
|
c26cf4dbec |
@ -59,6 +59,22 @@ builds:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
- id: casaos-riscv64
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
env:
|
||||
- CC=riscv64-linux-gnu-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- riscv64
|
||||
- id: casaos-migration-tool-amd64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
main: ./cmd/migration-tool
|
||||
@ -112,6 +128,23 @@ builds:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
- id: casaos-migration-tool-riscv64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=riscv64-linux-gnu-gcc
|
||||
gcflags:
|
||||
- all=-N -l
|
||||
ldflags:
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- riscv64
|
||||
archives:
|
||||
- name_template: >-
|
||||
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
|
||||
@ -120,6 +153,7 @@ archives:
|
||||
- casaos-amd64
|
||||
- casaos-arm64
|
||||
- casaos-arm-7
|
||||
- casaos-riscv64
|
||||
files:
|
||||
- build/**/*
|
||||
- name_template: >-
|
||||
@ -129,6 +163,7 @@ archives:
|
||||
- casaos-migration-tool-amd64
|
||||
- casaos-migration-tool-arm64
|
||||
- casaos-migration-tool-arm-7
|
||||
- casaos-migration-tool-riscv64
|
||||
files:
|
||||
- build/sysroot/etc/**/*
|
||||
checksum:
|
||||
|
@ -92,6 +92,30 @@ builds:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
- id: casaos-riscv64
|
||||
binary: build/sysroot/usr/bin/casaos
|
||||
env:
|
||||
- CC=riscv64-linux-gnu-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_id={{.Env.GoogleID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/google_drive.client_secret={{.Env.GoogleSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_id={{.Env.OneDriveID}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/onedrive.client_secret={{.Env.OneDriveSecret}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_key={{.Env.DropboxKey}}
|
||||
- -X github.com/IceWhaleTech/CasaOS/drivers/dropbox.app_secret={{.Env.DropboxSecret}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- riscv64
|
||||
- id: casaos-migration-tool-amd64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
hooks:
|
||||
@ -160,6 +184,25 @@ builds:
|
||||
- arm
|
||||
goarm:
|
||||
- "7"
|
||||
- id: casaos-migration-tool-riscv64
|
||||
binary: build/sysroot/usr/bin/casaos-migration-tool
|
||||
main: ./cmd/migration-tool
|
||||
env:
|
||||
- CC=riscv64-linux-gnu-gcc
|
||||
ldflags:
|
||||
- -X main.commit={{.Commit}}
|
||||
- -X main.date={{.Date}}
|
||||
- -s
|
||||
- -w
|
||||
- -extldflags "-static"
|
||||
tags:
|
||||
- musl
|
||||
- netgo
|
||||
- osusergo
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
- riscv64
|
||||
archives:
|
||||
- name_template: >-
|
||||
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
|
||||
@ -168,6 +211,7 @@ archives:
|
||||
- casaos-amd64
|
||||
- casaos-arm64
|
||||
- casaos-arm-7
|
||||
- casaos-riscv64
|
||||
files:
|
||||
- build/**/*
|
||||
- name_template: >-
|
||||
@ -177,6 +221,7 @@ archives:
|
||||
- casaos-migration-tool-amd64
|
||||
- casaos-migration-tool-arm64
|
||||
- casaos-migration-tool-arm-7
|
||||
- casaos-migration-tool-riscv64
|
||||
files:
|
||||
- build/sysroot/etc/**/*
|
||||
checksum:
|
||||
|
@ -208,7 +208,7 @@ Everyone's contribution is greatly appreciated. ([Emoji Key](https://allcontribu
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/jerrykuku"><img src="https://avatars.githubusercontent.com/u/9485680?v=4?s=100" width="100px;" alt=""/><br /><sub><b>老竭力</b></sub></a><br /><a href="https://github.com/IceWhaleTech/CasaOS/commits?author=jerrykuku" title="Code">💻</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=jerrykuku" title="Documentation">📖</a> <a href="#ideas-jerrykuku" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-jerrykuku" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-jerrykuku" title="Maintenance">🚧</a> <a href="#platform-jerrykuku" title="Packaging/porting to new platform">📦</a> <a href="#question-jerrykuku" title="Answering Questions">💬</a> <a href="https://github.com/IceWhaleTech/CasaOS/pulls?q=is%3Apr+reviewed-by%3Ajerrykuku" title="Reviewed Pull Requests">👀</a></td>
|
||||
<td align="center"><a href="https://github.com/LinkLeong"><img src="https://avatars.githubusercontent.com/u/13556972?v=4?s=100" width="100px;" alt=""/><br /><sub><b>link</b></sub></a><br /><a href="https://github.com/IceWhaleTech/CasaOS/commits?author=LinkLeong" title="Code">💻</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=LinkLeong" title="Documentation">📖</a> <a href="#ideas-LinkLeong" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-LinkLeong" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-LinkLeong" title="Maintenance">🚧</a> <a href="#question-LinkLeong" title="Answering Questions">💬</a> <a href="https://github.com/IceWhaleTech/CasaOS/pulls?q=is%3Apr+reviewed-by%3ALinkLeong" title="Reviewed Pull Requests">👀</a></td>
|
||||
<td align="center"><a href="https://github.com/tigerinus"><img src="https://avatars.githubusercontent.com/u/7172560?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tiger Wang (王豫)</b></sub></a><br /><a href="https://github.com/IceWhaleTech/CasaOS/commits?author=tigerinus" title="Code">💻</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=tigerinus" title="Documentation">📖</a> <a href="#ideas-tigerinus" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-tigerinus" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-tigerinus" title="Maintenance">🚧</a> <a href="#mentoring-tigerinus" title="Mentoring">🧑🏫</a> <a href="#security-tigerinus" title="Security">🛡️</a> <a href="#question-tigerinus" title="Answering Questions">💬</a> <a href="https://github.com/IceWhaleTech/CasaOS/pulls?q=is%3Apr+reviewed-by%3Atigerinus" title="Reviewed Pull Requests">👀</a></td>
|
||||
<td align="center"><a href="https://github.com/tigerinus"><img src="https://avatars.githubusercontent.com/u/7172560?v=4?s=100" width="100px;" alt=""/><br /><sub><b>太戈</b></sub></a><br /><a href="https://github.com/IceWhaleTech/CasaOS/commits?author=tigerinus" title="Code">💻</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=tigerinus" title="Documentation">📖</a> <a href="#ideas-tigerinus" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-tigerinus" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-tigerinus" title="Maintenance">🚧</a> <a href="#mentoring-tigerinus" title="Mentoring">🧑🏫</a> <a href="#security-tigerinus" title="Security">🛡️</a> <a href="#question-tigerinus" title="Answering Questions">💬</a> <a href="https://github.com/IceWhaleTech/CasaOS/pulls?q=is%3Apr+reviewed-by%3Atigerinus" title="Reviewed Pull Requests">👀</a></td>
|
||||
<td align="center"><a href="https://github.com/Lauren-ED209"><img src="https://avatars.githubusercontent.com/u/8243355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lauren</b></sub></a><br /><a href="#ideas-Lauren-ED209" title="Ideas, Planning, & Feedback">🤔</a> <a href="#fundingFinding-Lauren-ED209" title="Funding Finding">🔍</a> <a href="#projectManagement-Lauren-ED209" title="Project Management">📆</a> <a href="#question-Lauren-ED209" title="Answering Questions">💬</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=Lauren-ED209" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://JohnGuan.Cn"><img src="https://avatars.githubusercontent.com/u/3358477?v=4?s=100" width="100px;" alt=""/><br /><sub><b>John Guan</b></sub></a><br /><a href="#blog-JohnGuan" title="Blogposts">📝</a> <a href="#content-JohnGuan" title="Content">🖋</a> <a href="https://github.com/IceWhaleTech/CasaOS/commits?author=JohnGuan" title="Documentation">📖</a> <a href="#ideas-JohnGuan" title="Ideas, Planning, & Feedback">🤔</a> <a href="#eventOrganizing-JohnGuan" title="Event Organizing">📋</a> <a href="#mentoring-JohnGuan" title="Mentoring">🧑🏫</a> <a href="#question-JohnGuan" title="Answering Questions">💬</a> <a href="https://github.com/IceWhaleTech/CasaOS/pulls?q=is%3Apr+reviewed-by%3AJohnGuan" title="Reviewed Pull Requests">👀</a></td>
|
||||
<td align="center"><a href="https://blog.tippybits.com"><img src="https://avatars.githubusercontent.com/u/17506770?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David Tippett</b></sub></a><br /><a href="https://github.com/IceWhaleTech/CasaOS/commits?author=dtaivpp" title="Documentation">📖</a> <a href="#ideas-dtaivpp" title="Ideas, Planning, & Feedback">🤔</a> <a href="#question-dtaivpp" title="Answering Questions">💬</a></td>
|
||||
|
@ -111,6 +111,9 @@ aarch64)
|
||||
armv7l)
|
||||
ARCH="arm-7"
|
||||
;;
|
||||
riscv64)
|
||||
ARCH="riscv64"
|
||||
;;
|
||||
*)
|
||||
__error "Unsupported architecture"
|
||||
;;
|
||||
|
@ -2,7 +2,7 @@ package common
|
||||
|
||||
const (
|
||||
SERVICENAME = "casaos"
|
||||
VERSION = "0.4.14"
|
||||
VERSION = "0.4.15"
|
||||
BODY = " "
|
||||
RANW_NAME = "IceWhale-RemoteAccess"
|
||||
)
|
||||
|
@ -26,6 +26,7 @@ func (d *Onedrive) Config() driver.Config {
|
||||
func (d *Onedrive) GetAddition() driver.Additional {
|
||||
return &d.Addition
|
||||
}
|
||||
|
||||
func (d *Onedrive) Init(ctx context.Context) error {
|
||||
if d.ChunkSize < 1 {
|
||||
d.ChunkSize = 5
|
||||
@ -35,19 +36,20 @@ func (d *Onedrive) Init(ctx context.Context) error {
|
||||
}
|
||||
return d.refreshToken()
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
|
||||
url := d.GetMetaUrl(false, "/")
|
||||
user := Info{}
|
||||
resp, err := d.Request(url, http.MethodGet, nil, &user)
|
||||
_, err := d.Request(url, http.MethodGet, nil, &user)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
logger.Info("resp", zap.Any("resp", resp))
|
||||
return user.LastModifiedBy.User.DisplayName, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
|
||||
return user.CreatedBy.User.Email, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
|
||||
@ -63,6 +65,7 @@ func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string,
|
||||
total = strconv.Itoa(size.Total)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Onedrive) Drop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -43,19 +43,12 @@ type About struct {
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
LastModifiedBy struct {
|
||||
Application struct {
|
||||
DisplayName string `json:"displayName"`
|
||||
ID string `json:"id"`
|
||||
} `json:"application"`
|
||||
Device struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"device"`
|
||||
CreatedBy struct {
|
||||
User struct {
|
||||
Email string `json:"email"`
|
||||
DisplayName string `json:"displayName"`
|
||||
ID string `json:"id"`
|
||||
} `json:"user"`
|
||||
} `json:"lastModifiedBy"`
|
||||
} `json:"createdBy"`
|
||||
ParentReference struct {
|
||||
DriveID string `json:"driveId"`
|
||||
DriveType string `json:"driveType"`
|
||||
|
@ -3,11 +3,10 @@ package onedrive
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@ -15,6 +14,7 @@ var (
|
||||
client_id = "private build"
|
||||
client_secret = "private build"
|
||||
)
|
||||
|
||||
var onedriveHostMap = map[string]Host{
|
||||
"global": {
|
||||
Oauth: "https://login.microsoftonline.com",
|
||||
@ -34,31 +34,9 @@ var onedriveHostMap = map[string]Host{
|
||||
},
|
||||
}
|
||||
|
||||
func EncodePath(path string, all ...bool) string {
|
||||
seg := strings.Split(path, "/")
|
||||
toReplace := []struct {
|
||||
Src string
|
||||
Dst string
|
||||
}{
|
||||
{Src: "%", Dst: "%25"},
|
||||
{"%", "%25"},
|
||||
{"?", "%3F"},
|
||||
{"#", "%23"},
|
||||
}
|
||||
for i := range seg {
|
||||
if len(all) > 0 && all[0] {
|
||||
seg[i] = url.PathEscape(seg[i])
|
||||
} else {
|
||||
for j := range toReplace {
|
||||
seg[i] = strings.ReplaceAll(seg[i], toReplace[j].Src, toReplace[j].Dst)
|
||||
}
|
||||
}
|
||||
}
|
||||
return strings.Join(seg, "/")
|
||||
}
|
||||
func (d *Onedrive) GetMetaUrl(auth bool, path string) string {
|
||||
host := onedriveHostMap[d.Region]
|
||||
path = EncodePath(path, true)
|
||||
path = utils.EncodePath(path, true)
|
||||
if auth {
|
||||
return host.Oauth
|
||||
}
|
||||
|
@ -16,23 +16,6 @@ import (
|
||||
)
|
||||
|
||||
func ListStorages(ctx echo.Context) error {
|
||||
// var req model.PageReq
|
||||
// if err := ctx.Bind(&req); err != nil {
|
||||
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: err.Error()})
|
||||
// return
|
||||
// }
|
||||
// req.Validate()
|
||||
|
||||
// logger.Info("ListStorages", zap.Any("req", req))
|
||||
// storages, total, err := service.MyService.Storage().GetStorages(req.Page, req.PerPage)
|
||||
// if err != nil {
|
||||
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||
// return
|
||||
// }
|
||||
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: model.PageResp{
|
||||
// Content: storages,
|
||||
// Total: total,
|
||||
// }})
|
||||
r, err := service.MyService.Storage().GetStorages()
|
||||
if err != nil {
|
||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||
@ -58,12 +41,7 @@ func ListStorages(ctx echo.Context) error {
|
||||
list := []httper.MountPoint{}
|
||||
|
||||
for _, v := range r.MountPoints {
|
||||
list = append(list, httper.MountPoint{
|
||||
Fs: v.Fs,
|
||||
Icon: v.Icon,
|
||||
MountPoint: v.MountPoint,
|
||||
Name: v.Name,
|
||||
})
|
||||
list = append(list, httper.MountPoint(v))
|
||||
}
|
||||
|
||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list})
|
||||
|
@ -1,6 +1,8 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -15,49 +17,47 @@ import (
|
||||
)
|
||||
|
||||
func GetRecoverStorage(ctx echo.Context) error {
|
||||
ctx.Request().Header.Add("Content-Type", "text/html; charset=utf-8")
|
||||
t := ctx.Param("type")
|
||||
t := strings.TrimSuffix(ctx.Param("type"), "/")
|
||||
currentTime := time.Now().UTC()
|
||||
currentDate := time.Now().UTC().Format("2006-01-02")
|
||||
notify := make(map[string]interface{})
|
||||
event := "casaos:file:recover"
|
||||
if t == "GoogleDrive" {
|
||||
google_drive := google_drive.GetConfig()
|
||||
google_drive.Code = ctx.QueryParam("code")
|
||||
if len(google_drive.Code) == 0 {
|
||||
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Code cannot be empty"
|
||||
logger.Error("Then code is empty: ", zap.String("code", google_drive.Code), zap.Any("name", "google_drive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||
}
|
||||
|
||||
err := google_drive.Init(ctx.Request().Context())
|
||||
err := google_drive.Init(context.Background())
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Initialization failure"
|
||||
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "google_drive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
|
||||
username, err := google_drive.GetUserInfo(ctx.Request().Context())
|
||||
username, err := google_drive.GetUserInfo(context.Background())
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Failed to get user information"
|
||||
logger.Error("Then get user info error: ", zap.Error(err), zap.Any("name", "google_drive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
dmap := make(map[string]string)
|
||||
dmap["username"] = username
|
||||
configs, err := service.MyService.Storage().GetConfig()
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Failed to get rclone config"
|
||||
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "google_drive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
for _, v := range configs.Remotes {
|
||||
cf, err := service.MyService.Storage().GetConfigByName(v)
|
||||
@ -66,14 +66,14 @@ func GetRecoverStorage(ctx echo.Context) error {
|
||||
continue
|
||||
}
|
||||
if cf["type"] == "drive" && cf["username"] == dmap["username"] {
|
||||
ctx.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||
err := service.MyService.Storage().CheckAndMountByName(v)
|
||||
if err != nil {
|
||||
logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
|
||||
}
|
||||
notify["status"] = "warn"
|
||||
notify["message"] = "The same configuration has been added"
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||
}
|
||||
}
|
||||
if len(username) > 0 {
|
||||
@ -81,7 +81,6 @@ func GetRecoverStorage(ctx echo.Context) error {
|
||||
username = a[0]
|
||||
}
|
||||
|
||||
// username = fileutil.NameAccumulation(username, "/mnt")
|
||||
username += "_google_drive_" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
|
||||
dmap["client_id"] = google_drive.ClientID
|
||||
@ -95,44 +94,45 @@ func GetRecoverStorage(ctx echo.Context) error {
|
||||
notify["status"] = "success"
|
||||
notify["message"] = "Success"
|
||||
notify["driver"] = "GoogleDrive"
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
} else if t == "Dropbox" {
|
||||
dropbox := dropbox.GetConfig()
|
||||
|
||||
dropbox.Code = ctx.QueryParam("code")
|
||||
if len(dropbox.Code) == 0 {
|
||||
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Code cannot be empty"
|
||||
logger.Error("Then code is empty error: ", zap.String("code", dropbox.Code), zap.Any("name", "dropbox"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||
}
|
||||
|
||||
err := dropbox.Init(ctx.Request().Context())
|
||||
err := dropbox.Init(context.Background())
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Initialization failure"
|
||||
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "dropbox"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
username, err := dropbox.GetUserInfo(ctx.Request().Context())
|
||||
username, err := dropbox.GetUserInfo(context.Background())
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Failed to get user information"
|
||||
logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "dropbox"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
dmap := make(map[string]string)
|
||||
dmap["username"] = username
|
||||
|
||||
configs, err := service.MyService.Storage().GetConfig()
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Failed to get rclone config"
|
||||
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "dropbox"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
for _, v := range configs.Remotes {
|
||||
cf, err := service.MyService.Storage().GetConfigByName(v)
|
||||
@ -141,15 +141,14 @@ func GetRecoverStorage(ctx echo.Context) error {
|
||||
continue
|
||||
}
|
||||
if cf["type"] == "dropbox" && cf["username"] == dmap["username"] {
|
||||
ctx.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||
err := service.MyService.Storage().CheckAndMountByName(v)
|
||||
if err != nil {
|
||||
if err := service.MyService.Storage().CheckAndMountByName(v); err != nil {
|
||||
logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
|
||||
}
|
||||
|
||||
notify["status"] = "warn"
|
||||
notify["message"] = "The same configuration has been added"
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||
}
|
||||
}
|
||||
if len(username) > 0 {
|
||||
@ -162,62 +161,49 @@ func GetRecoverStorage(ctx echo.Context) error {
|
||||
dmap["client_secret"] = dropbox.AppSecret
|
||||
dmap["token"] = `{"access_token":"` + dropbox.AccessToken + `","token_type":"bearer","refresh_token":"` + dropbox.Addition.RefreshToken + `","expiry":"` + currentDate + `T` + currentTime.Add(time.Hour*3).Add(time.Minute*50).Format("15:04:05") + `.780385354Z"}`
|
||||
dmap["mount_point"] = "/mnt/" + username
|
||||
// data.SetValue(username, "type", "dropbox")
|
||||
// data.SetValue(username, "client_id", add.AppKey)
|
||||
// data.SetValue(username, "client_secret", add.AppSecret)
|
||||
// data.SetValue(username, "mount_point", "/mnt/"+username)
|
||||
|
||||
// data.SetValue(username, "token", `{"access_token":"`+dropbox.AccessToken+`","token_type":"bearer","refresh_token":"`+dropbox.Addition.RefreshToken+`","expiry":"`+currentDate+`T`+currentTime.Add(time.Hour*3).Format("15:04:05")+`.780385354Z"}`)
|
||||
// e = data.Save()
|
||||
// if e != nil {
|
||||
// return ctx.String(200, `<p>保存配置失败:`+e.Error()+`</p>`)
|
||||
|
||||
// return
|
||||
// }
|
||||
service.MyService.Storage().CreateConfig(dmap, username, "dropbox")
|
||||
service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
|
||||
|
||||
notify["status"] = "success"
|
||||
notify["message"] = "Success"
|
||||
notify["driver"] = "Dropbox"
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
} else if t == "Onedrive" {
|
||||
onedrive := onedrive.GetConfig()
|
||||
onedrive.Code = ctx.QueryParam("code")
|
||||
if len(onedrive.Code) == 0 {
|
||||
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Code cannot be empty"
|
||||
logger.Error("Then code is empty error: ", zap.String("code", onedrive.Code), zap.Any("name", "onedrive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||
}
|
||||
|
||||
err := onedrive.Init(ctx.Request().Context())
|
||||
err := onedrive.Init(context.Background())
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Initialization failure"
|
||||
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "onedrive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
username, driveId, driveType, err := onedrive.GetInfo(ctx.Request().Context())
|
||||
username, driveId, driveType, err := onedrive.GetInfo(context.Background())
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Failed to get user information"
|
||||
logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "onedrive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
dmap := make(map[string]string)
|
||||
dmap["username"] = username
|
||||
|
||||
configs, err := service.MyService.Storage().GetConfig()
|
||||
if err != nil {
|
||||
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
notify["status"] = "fail"
|
||||
notify["message"] = "Failed to get rclone config"
|
||||
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "onedrive"))
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||
}
|
||||
for _, v := range configs.Remotes {
|
||||
cf, err := service.MyService.Storage().GetConfigByName(v)
|
||||
@ -226,15 +212,14 @@ func GetRecoverStorage(ctx echo.Context) error {
|
||||
continue
|
||||
}
|
||||
if cf["type"] == "onedrive" && cf["username"] == dmap["username"] {
|
||||
ctx.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||
err := service.MyService.Storage().CheckAndMountByName(v)
|
||||
if err != nil {
|
||||
if err := service.MyService.Storage().CheckAndMountByName(v); err != nil {
|
||||
logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
|
||||
}
|
||||
|
||||
notify["status"] = "warn"
|
||||
notify["message"] = "The same configuration has been added"
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
return ctx.HTML(http.StatusOK, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||
}
|
||||
}
|
||||
if len(username) > 0 {
|
||||
@ -249,26 +234,14 @@ func GetRecoverStorage(ctx echo.Context) error {
|
||||
dmap["mount_point"] = "/mnt/" + username
|
||||
dmap["drive_id"] = driveId
|
||||
dmap["drive_type"] = driveType
|
||||
// data.SetValue(username, "type", "dropbox")
|
||||
// data.SetValue(username, "client_id", add.AppKey)
|
||||
// data.SetValue(username, "client_secret", add.AppSecret)
|
||||
// data.SetValue(username, "mount_point", "/mnt/"+username)
|
||||
|
||||
// data.SetValue(username, "token", `{"access_token":"`+dropbox.AccessToken+`","token_type":"bearer","refresh_token":"`+dropbox.Addition.RefreshToken+`","expiry":"`+currentDate+`T`+currentTime.Add(time.Hour*3).Format("15:04:05")+`.780385354Z"}`)
|
||||
// e = data.Save()
|
||||
// if e != nil {
|
||||
// return ctx.String(200, `<p>保存配置失败:`+e.Error()+`</p>`)
|
||||
|
||||
// return
|
||||
// }
|
||||
service.MyService.Storage().CreateConfig(dmap, username, "onedrive")
|
||||
service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
|
||||
|
||||
notify["status"] = "success"
|
||||
notify["message"] = "Success"
|
||||
notify["driver"] = "Onedrive"
|
||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||
service.MyService.Notify().SendNotify(event, notify)
|
||||
}
|
||||
|
||||
return ctx.String(200, `<p>Just close the page</p><script>window.close()</script>`)
|
||||
return ctx.HTML(200, `<p>Just close the page</p><script>window.close()</script>`)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user