Compare commits

..

No commits in common. "main" and "v0.4.10" have entirely different histories.

16 changed files with 153 additions and 198 deletions

View File

@ -1,19 +0,0 @@
name: Sync OpenAPI
on:
workflow_call:
inputs:
project-name:
required: true
type: string
push:
branches:
- main
jobs:
sync:
uses: IceWhaleTech/github/.github/workflows/sync_openapi.yml@main
with:
project-name: casaos
secrets:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}

View File

@ -1,19 +0,0 @@
name: Sync OpenAPI
on:
workflow_call:
inputs:
project-name:
required: true
type: string
push:
branches:
- main
jobs:
sync:
uses: IceWhaleTech/github/.github/workflows/sync_openapi.yml@main
with:
project-name: casaos
secrets:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}

View File

@ -59,22 +59,6 @@ builds:
- arm - arm
goarm: goarm:
- "7" - "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 - id: casaos-migration-tool-amd64
binary: build/sysroot/usr/bin/casaos-migration-tool binary: build/sysroot/usr/bin/casaos-migration-tool
main: ./cmd/migration-tool main: ./cmd/migration-tool
@ -128,23 +112,6 @@ builds:
- arm - arm
goarm: goarm:
- "7" - "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: archives:
- name_template: >- - name_template: >-
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }} {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
@ -153,7 +120,6 @@ archives:
- casaos-amd64 - casaos-amd64
- casaos-arm64 - casaos-arm64
- casaos-arm-7 - casaos-arm-7
- casaos-riscv64
files: files:
- build/**/* - build/**/*
- name_template: >- - name_template: >-
@ -163,7 +129,6 @@ archives:
- casaos-migration-tool-amd64 - casaos-migration-tool-amd64
- casaos-migration-tool-arm64 - casaos-migration-tool-arm64
- casaos-migration-tool-arm-7 - casaos-migration-tool-arm-7
- casaos-migration-tool-riscv64
files: files:
- build/sysroot/etc/**/* - build/sysroot/etc/**/*
checksum: checksum:

View File

@ -92,30 +92,6 @@ builds:
- arm - arm
goarm: goarm:
- "7" - "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 - id: casaos-migration-tool-amd64
binary: build/sysroot/usr/bin/casaos-migration-tool binary: build/sysroot/usr/bin/casaos-migration-tool
hooks: hooks:
@ -184,25 +160,6 @@ builds:
- arm - arm
goarm: goarm:
- "7" - "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: archives:
- name_template: >- - name_template: >-
{{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }} {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
@ -211,7 +168,6 @@ archives:
- casaos-amd64 - casaos-amd64
- casaos-arm64 - casaos-arm64
- casaos-arm-7 - casaos-arm-7
- casaos-riscv64
files: files:
- build/**/* - build/**/*
- name_template: >- - name_template: >-
@ -221,7 +177,6 @@ archives:
- casaos-migration-tool-amd64 - casaos-migration-tool-amd64
- casaos-migration-tool-arm64 - casaos-migration-tool-arm64
- casaos-migration-tool-arm-7 - casaos-migration-tool-arm-7
- casaos-migration-tool-riscv64
files: files:
- build/sysroot/etc/**/* - build/sysroot/etc/**/*
checksum: checksum:

View File

@ -194,6 +194,9 @@ CasaOS is a community-driven open source project and the people involved are Cas
- See <https://wiki.casaos.io/en/contribute> for ways of contributing to CasaOS - See <https://wiki.casaos.io/en/contribute> for ways of contributing to CasaOS
- See <https://wiki.casaos.io/en/contribute/development> if you want to be involved in code contribution specifically - See <https://wiki.casaos.io/en/contribute/development> if you want to be involved in code contribution specifically
## Donate
<p ><a href="https://www.buymeacoffee.com/icewhaletech"> <img align="center" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="50" width="210" alt="bappi2097" target="_blank" /></a></p>
## Credits ## Credits
@ -208,7 +211,7 @@ Everyone's contribution is greatly appreciated. ([Emoji Key](https://allcontribu
<tr> <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/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/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>太戈</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>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/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://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://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> <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>

View File

@ -111,9 +111,6 @@ aarch64)
armv7l) armv7l)
ARCH="arm-7" ARCH="arm-7"
;; ;;
riscv64)
ARCH="riscv64"
;;
*) *)
__error "Unsupported architecture" __error "Unsupported architecture"
;; ;;

View File

@ -2,7 +2,7 @@ package common
const ( const (
SERVICENAME = "casaos" SERVICENAME = "casaos"
VERSION = "0.4.15" VERSION = "0.4.10"
BODY = " " BODY = " "
RANW_NAME = "IceWhale-RemoteAccess" RANW_NAME = "IceWhale-RemoteAccess"
) )

View File

@ -26,7 +26,6 @@ func (d *Onedrive) Config() driver.Config {
func (d *Onedrive) GetAddition() driver.Additional { func (d *Onedrive) GetAddition() driver.Additional {
return &d.Addition return &d.Addition
} }
func (d *Onedrive) Init(ctx context.Context) error { func (d *Onedrive) Init(ctx context.Context) error {
if d.ChunkSize < 1 { if d.ChunkSize < 1 {
d.ChunkSize = 5 d.ChunkSize = 5
@ -36,20 +35,19 @@ func (d *Onedrive) Init(ctx context.Context) error {
} }
return d.refreshToken() return d.refreshToken()
} }
func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) { func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
return "", nil return "", nil
} }
func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) { func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
url := d.GetMetaUrl(false, "/") url := d.GetMetaUrl(false, "/")
user := Info{} user := Info{}
_, err := d.Request(url, http.MethodGet, nil, &user) resp, err := d.Request(url, http.MethodGet, nil, &user)
if err != nil { if err != nil {
return "", "", "", err return "", "", "", err
} }
return user.CreatedBy.User.Email, user.ParentReference.DriveID, user.ParentReference.DriveType, nil logger.Info("resp", zap.Any("resp", resp))
return user.LastModifiedBy.User.DisplayName, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
} }
func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) { func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
@ -65,7 +63,6 @@ func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string,
total = strconv.Itoa(size.Total) total = strconv.Itoa(size.Total)
return return
} }
func (d *Onedrive) Drop(ctx context.Context) error { func (d *Onedrive) Drop(ctx context.Context) error {
return nil return nil
} }

View File

@ -43,12 +43,19 @@ type About struct {
} }
type Info struct { type Info struct {
CreatedBy struct { LastModifiedBy struct {
User struct { Application struct {
Email string `json:"email"`
DisplayName string `json:"displayName"` DisplayName string `json:"displayName"`
ID string `json:"id"`
} `json:"application"`
Device struct {
ID string `json:"id"`
} `json:"device"`
User struct {
DisplayName string `json:"displayName"`
ID string `json:"id"`
} `json:"user"` } `json:"user"`
} `json:"createdBy"` } `json:"lastModifiedBy"`
ParentReference struct { ParentReference struct {
DriveID string `json:"driveId"` DriveID string `json:"driveId"`
DriveType string `json:"driveType"` DriveType string `json:"driveType"`

View File

@ -3,10 +3,11 @@ package onedrive
import ( import (
"errors" "errors"
"fmt" "fmt"
"net/url"
"strings"
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" "github.com/IceWhaleTech/CasaOS-Common/utils/logger"
"github.com/IceWhaleTech/CasaOS/drivers/base" "github.com/IceWhaleTech/CasaOS/drivers/base"
"github.com/IceWhaleTech/CasaOS/pkg/utils"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -14,7 +15,6 @@ var (
client_id = "private build" client_id = "private build"
client_secret = "private build" client_secret = "private build"
) )
var onedriveHostMap = map[string]Host{ var onedriveHostMap = map[string]Host{
"global": { "global": {
Oauth: "https://login.microsoftonline.com", Oauth: "https://login.microsoftonline.com",
@ -34,9 +34,31 @@ 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 { func (d *Onedrive) GetMetaUrl(auth bool, path string) string {
host := onedriveHostMap[d.Region] host := onedriveHostMap[d.Region]
path = utils.EncodePath(path, true) path = EncodePath(path, true)
if auth { if auth {
return host.Oauth return host.Oauth
} }

7
go.mod
View File

@ -4,7 +4,7 @@ go 1.21
require ( require (
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d
github.com/IceWhaleTech/CasaOS-Common v0.4.11-alpha4 github.com/IceWhaleTech/CasaOS-Common v0.4.9-alpha6
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
github.com/deckarep/golang-set/v2 v2.3.0 github.com/deckarep/golang-set/v2 v2.3.0
github.com/deepmap/oapi-codegen v1.12.4 github.com/deepmap/oapi-codegen v1.12.4
@ -17,7 +17,7 @@ require (
github.com/golang/mock v1.6.0 github.com/golang/mock v1.6.0
github.com/gomodule/redigo v1.8.9 github.com/gomodule/redigo v1.8.9
github.com/google/go-github/v36 v36.0.0 github.com/google/go-github/v36 v36.0.0
github.com/google/uuid v1.5.0 github.com/google/uuid v1.3.0
github.com/googollee/go-socket.io v1.7.0 github.com/googollee/go-socket.io v1.7.0
github.com/gorilla/websocket v1.5.0 github.com/gorilla/websocket v1.5.0
github.com/h2non/filetype v1.1.3 github.com/h2non/filetype v1.1.3
@ -66,7 +66,6 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
github.com/golang/protobuf v1.5.3 // indirect github.com/golang/protobuf v1.5.3 // indirect
@ -79,7 +78,7 @@ require (
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect github.com/klauspost/pgzip v1.2.5 // indirect
github.com/labstack/echo-jwt/v4 v4.2.0 // indirect github.com/labstack/echo-jwt/v4 v4.2.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect github.com/labstack/gommon v0.4.2 // indirect

14
go.sum
View File

@ -1,7 +1,7 @@
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d h1:62lEBImTxZ83pgzywgDNIrPPuQ+j4ep9QjqrWBn1hrU= github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d h1:62lEBImTxZ83pgzywgDNIrPPuQ+j4ep9QjqrWBn1hrU=
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d/go.mod h1:lW9x+yEjqKdPbE3+cf2fGPJXCw/hChX3Omi9QHTLFsQ= github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d/go.mod h1:lW9x+yEjqKdPbE3+cf2fGPJXCw/hChX3Omi9QHTLFsQ=
github.com/IceWhaleTech/CasaOS-Common v0.4.11-alpha4 h1:W+kOJ3NcWCEAnZdjqmnjnhAG+aLbiVNXnOvV+1bHsB0= github.com/IceWhaleTech/CasaOS-Common v0.4.9-alpha6 h1:ojExdb1fZDieTBYgNwopHAsW4FMGKkat4id8YwyyE0g=
github.com/IceWhaleTech/CasaOS-Common v0.4.11-alpha4/go.mod h1:513p+6RXPBFr98GQZbY1TCyt6Q0jWiuK6vh+gBTmNwA= github.com/IceWhaleTech/CasaOS-Common v0.4.9-alpha6/go.mod h1:W/768nPd9BJXh+a72y8hUJNcmjDvyMqlXxlT+lOT3t4=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
@ -84,8 +84,6 @@ github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
@ -121,8 +119,8 @@ github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbu
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f h1:o2yGZLlsOj5H5uvtQNEdi6DeA0GbUP3lm0gWW5RvY0s= github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f h1:o2yGZLlsOj5H5uvtQNEdi6DeA0GbUP3lm0gWW5RvY0s=
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f/go.mod h1:H3K1Iu/utuCfa10JO+GsmKUYSWi7ug57Rk6GaDRHaaQ= github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f/go.mod h1:H3K1Iu/utuCfa10JO+GsmKUYSWi7ug57Rk6GaDRHaaQ=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googollee/go-socket.io v1.7.0 h1:ODcQSAvVIPvKozXtUGuJDV3pLwdpBLDs1Uoq/QHIlY8= github.com/googollee/go-socket.io v1.7.0 h1:ODcQSAvVIPvKozXtUGuJDV3pLwdpBLDs1Uoq/QHIlY8=
github.com/googollee/go-socket.io v1.7.0/go.mod h1:0vGP8/dXR9SZUMMD4+xxaGo/lohOw3YWMh2WRiWeKxg= github.com/googollee/go-socket.io v1.7.0/go.mod h1:0vGP8/dXR9SZUMMD4+xxaGo/lohOw3YWMh2WRiWeKxg=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
@ -150,8 +148,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE= github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=

View File

@ -179,7 +179,7 @@ func CreateFileAndWriteContent(path string, content string) error {
return nil return nil
} }
// IsNotExistCreateFile create a file if it does not exist // IsNotExistMkDir create a directory if it does not exist
func IsNotExistCreateFile(src string) error { func IsNotExistCreateFile(src string) error {
if notExist := CheckNotExist(src); notExist { if notExist := CheckNotExist(src); notExist {
if err := CreateFile(src); err != nil { if err := CreateFile(src); err != nil {

View File

@ -16,6 +16,23 @@ import (
) )
func ListStorages(ctx echo.Context) error { 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() r, err := service.MyService.Storage().GetStorages()
if err != nil { 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 ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
@ -41,7 +58,12 @@ func ListStorages(ctx echo.Context) error {
list := []httper.MountPoint{} list := []httper.MountPoint{}
for _, v := range r.MountPoints { for _, v := range r.MountPoints {
list = append(list, httper.MountPoint(v)) list = append(list, httper.MountPoint{
Fs: v.Fs,
Icon: v.Icon,
MountPoint: v.MountPoint,
Name: v.Name,
})
} }
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list}) return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list})

View File

@ -257,6 +257,7 @@ func GetDownloadSingleFile(ctx echo.Context) error {
ctx.Request().Header.Add("Content-Length", strconv.FormatInt(node.Size(), 10)) ctx.Request().Header.Add("Content-Length", strconv.FormatInt(node.Size(), 10))
} }
http.ServeContent(ctx.Response().Writer, ctx.Request(), fileName, node.ModTime(), fi) http.ServeContent(ctx.Response().Writer, ctx.Request(), fileName, node.ModTime(), fi)
// http.ServeFile(c.Writer, ctx.Request(), filePath)
defer fi.Close() defer fi.Close()
fileTmp, err := os.Open(filePath) fileTmp, err := os.Open(filePath)
if err != nil { if err != nil {
@ -267,7 +268,7 @@ func GetDownloadSingleFile(ctx echo.Context) error {
} }
defer fileTmp.Close() defer fileTmp.Close()
return nil return ctx.File(filePath)
} }
// @Summary 获取目录列表 // @Summary 获取目录列表

View File

@ -1,8 +1,6 @@
package v1 package v1
import ( import (
"context"
"net/http"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -17,47 +15,49 @@ import (
) )
func GetRecoverStorage(ctx echo.Context) error { func GetRecoverStorage(ctx echo.Context) error {
t := strings.TrimSuffix(ctx.Param("type"), "/") ctx.Request().Header.Add("Content-Type", "text/html; charset=utf-8")
t := ctx.Param("type")
currentTime := time.Now().UTC() currentTime := time.Now().UTC()
currentDate := time.Now().UTC().Format("2006-01-02") currentDate := time.Now().UTC().Format("2006-01-02")
notify := make(map[string]interface{}) notify := make(map[string]interface{})
event := "casaos:file:recover"
if t == "GoogleDrive" { if t == "GoogleDrive" {
google_drive := google_drive.GetConfig() google_drive := google_drive.GetConfig()
google_drive.Code = ctx.QueryParam("code") google_drive.Code = ctx.QueryParam("code")
if len(google_drive.Code) == 0 { if len(google_drive.Code) == 0 {
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Code cannot be empty" notify["message"] = "Code cannot be empty"
logger.Error("Then code is empty: ", zap.String("code", google_drive.Code), zap.Any("name", "google_drive")) 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) 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(context.Background())
err := google_drive.Init(ctx.Request().Context())
if err != nil { if err != nil {
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Initialization failure" notify["message"] = "Initialization failure"
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "google_drive")) logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "google_drive"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
} }
username, err := google_drive.GetUserInfo(context.Background()) username, err := google_drive.GetUserInfo(ctx.Request().Context())
if err != nil { if err != nil {
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Failed to get user information" notify["message"] = "Failed to get user information"
logger.Error("Then get user info error: ", zap.Error(err), zap.Any("name", "google_drive")) logger.Error("Then get user info error: ", zap.Error(err), zap.Any("name", "google_drive"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", 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 := make(map[string]string)
dmap["username"] = username dmap["username"] = username
configs, err := service.MyService.Storage().GetConfig() configs, err := service.MyService.Storage().GetConfig()
if err != nil { if err != nil {
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Failed to get rclone config" notify["message"] = "Failed to get rclone config"
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "google_drive")) logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "google_drive"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
} }
for _, v := range configs.Remotes { for _, v := range configs.Remotes {
cf, err := service.MyService.Storage().GetConfigByName(v) cf, err := service.MyService.Storage().GetConfigByName(v)
@ -66,14 +66,14 @@ func GetRecoverStorage(ctx echo.Context) error {
continue continue
} }
if cf["type"] == "drive" && cf["username"] == dmap["username"] { 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) err := service.MyService.Storage().CheckAndMountByName(v)
if err != nil { if err != nil {
logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"])) logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
} }
notify["status"] = "warn" notify["status"] = "warn"
notify["message"] = "The same configuration has been added" notify["message"] = "The same configuration has been added"
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>The same configuration has been added</p><script>window.close()</script>`)
} }
} }
if len(username) > 0 { if len(username) > 0 {
@ -81,6 +81,7 @@ func GetRecoverStorage(ctx echo.Context) error {
username = a[0] username = a[0]
} }
// username = fileutil.NameAccumulation(username, "/mnt")
username += "_google_drive_" + strconv.FormatInt(time.Now().Unix(), 10) username += "_google_drive_" + strconv.FormatInt(time.Now().Unix(), 10)
dmap["client_id"] = google_drive.ClientID dmap["client_id"] = google_drive.ClientID
@ -94,45 +95,44 @@ func GetRecoverStorage(ctx echo.Context) error {
notify["status"] = "success" notify["status"] = "success"
notify["message"] = "Success" notify["message"] = "Success"
notify["driver"] = "GoogleDrive" notify["driver"] = "GoogleDrive"
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
} else if t == "Dropbox" { } else if t == "Dropbox" {
dropbox := dropbox.GetConfig() dropbox := dropbox.GetConfig()
dropbox.Code = ctx.QueryParam("code") dropbox.Code = ctx.QueryParam("code")
if len(dropbox.Code) == 0 { if len(dropbox.Code) == 0 {
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Code cannot be empty" notify["message"] = "Code cannot be empty"
logger.Error("Then code is empty error: ", zap.String("code", dropbox.Code), zap.Any("name", "dropbox")) logger.Error("Then code is empty error: ", zap.String("code", dropbox.Code), zap.Any("name", "dropbox"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Code cannot be empty</p><script>window.close()</script>`)
} }
err := dropbox.Init(context.Background())
err := dropbox.Init(ctx.Request().Context())
if err != nil { if err != nil {
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Initialization failure" notify["message"] = "Initialization failure"
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "dropbox")) logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "dropbox"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
} }
username, err := dropbox.GetUserInfo(context.Background()) username, err := dropbox.GetUserInfo(ctx.Request().Context())
if err != nil { if err != nil {
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Failed to get user information" notify["message"] = "Failed to get user information"
logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "dropbox")) logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "dropbox"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", 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 := make(map[string]string)
dmap["username"] = username dmap["username"] = username
configs, err := service.MyService.Storage().GetConfig() configs, err := service.MyService.Storage().GetConfig()
if err != nil { if err != nil {
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Failed to get rclone config" notify["message"] = "Failed to get rclone config"
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "dropbox")) logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "dropbox"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
} }
for _, v := range configs.Remotes { for _, v := range configs.Remotes {
cf, err := service.MyService.Storage().GetConfigByName(v) cf, err := service.MyService.Storage().GetConfigByName(v)
@ -141,14 +141,15 @@ func GetRecoverStorage(ctx echo.Context) error {
continue continue
} }
if cf["type"] == "dropbox" && cf["username"] == dmap["username"] { if cf["type"] == "dropbox" && cf["username"] == dmap["username"] {
if err := service.MyService.Storage().CheckAndMountByName(v); err != nil { 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"])) logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
} }
notify["status"] = "warn" notify["status"] = "warn"
notify["message"] = "The same configuration has been added" notify["message"] = "The same configuration has been added"
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>The same configuration has been added</p><script>window.close()</script>`)
} }
} }
if len(username) > 0 { if len(username) > 0 {
@ -161,49 +162,62 @@ func GetRecoverStorage(ctx echo.Context) error {
dmap["client_secret"] = dropbox.AppSecret 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["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 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().CreateConfig(dmap, username, "dropbox")
service.MyService.Storage().MountStorage("/mnt/"+username, username+":") service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
notify["status"] = "success" notify["status"] = "success"
notify["message"] = "Success" notify["message"] = "Success"
notify["driver"] = "Dropbox" notify["driver"] = "Dropbox"
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
} else if t == "Onedrive" { } else if t == "Onedrive" {
onedrive := onedrive.GetConfig() onedrive := onedrive.GetConfig()
onedrive.Code = ctx.QueryParam("code") onedrive.Code = ctx.QueryParam("code")
if len(onedrive.Code) == 0 { if len(onedrive.Code) == 0 {
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Code cannot be empty" notify["message"] = "Code cannot be empty"
logger.Error("Then code is empty error: ", zap.String("code", onedrive.Code), zap.Any("name", "onedrive")) logger.Error("Then code is empty error: ", zap.String("code", onedrive.Code), zap.Any("name", "onedrive"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Code cannot be empty</p><script>window.close()</script>`)
} }
err := onedrive.Init(context.Background())
err := onedrive.Init(ctx.Request().Context())
if err != nil { if err != nil {
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Initialization failure" notify["message"] = "Initialization failure"
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "onedrive")) logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "onedrive"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
} }
username, driveId, driveType, err := onedrive.GetInfo(context.Background()) username, driveId, driveType, err := onedrive.GetInfo(ctx.Request().Context())
if err != nil { if err != nil {
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Failed to get user information" notify["message"] = "Failed to get user information"
logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "onedrive")) logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "onedrive"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", 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 := make(map[string]string)
dmap["username"] = username dmap["username"] = username
configs, err := service.MyService.Storage().GetConfig() configs, err := service.MyService.Storage().GetConfig()
if err != nil { if err != nil {
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail" notify["status"] = "fail"
notify["message"] = "Failed to get rclone config" notify["message"] = "Failed to get rclone config"
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "onedrive")) logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "onedrive"))
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
} }
for _, v := range configs.Remotes { for _, v := range configs.Remotes {
cf, err := service.MyService.Storage().GetConfigByName(v) cf, err := service.MyService.Storage().GetConfigByName(v)
@ -212,14 +226,15 @@ func GetRecoverStorage(ctx echo.Context) error {
continue continue
} }
if cf["type"] == "onedrive" && cf["username"] == dmap["username"] { if cf["type"] == "onedrive" && cf["username"] == dmap["username"] {
if err := service.MyService.Storage().CheckAndMountByName(v); err != nil { 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"])) logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
} }
notify["status"] = "warn" notify["status"] = "warn"
notify["message"] = "The same configuration has been added" notify["message"] = "The same configuration has been added"
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
return ctx.HTML(http.StatusOK, `<p>The same configuration has been added</p><script>window.close()</script>`)
} }
} }
if len(username) > 0 { if len(username) > 0 {
@ -234,14 +249,26 @@ func GetRecoverStorage(ctx echo.Context) error {
dmap["mount_point"] = "/mnt/" + username dmap["mount_point"] = "/mnt/" + username
dmap["drive_id"] = driveId dmap["drive_id"] = driveId
dmap["drive_type"] = driveType 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().CreateConfig(dmap, username, "onedrive")
service.MyService.Storage().MountStorage("/mnt/"+username, username+":") service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
notify["status"] = "success" notify["status"] = "success"
notify["message"] = "Success" notify["message"] = "Success"
notify["driver"] = "Onedrive" notify["driver"] = "Onedrive"
service.MyService.Notify().SendNotify(event, notify) service.MyService.Notify().SendNotify("casaos:file:recover", notify)
} }
return ctx.HTML(200, `<p>Just close the page</p><script>window.close()</script>`) return ctx.String(200, `<p>Just close the page</p><script>window.close()</script>`)
} }