Skip to content

Commit

Permalink
feat: add dir search
Browse files Browse the repository at this point in the history
  • Loading branch information
lwydyby committed Jun 5, 2024
1 parent 97e7c7e commit 272ce20
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN cd front && yarn install && yarn build
FROM golang:1.22 AS go_builder
WORKDIR /app
COPY . .
COPY --from=node_builder /app/front/dist ./front/
COPY --from=node_builder /app/front/dist ./front/dist
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o aliyun .

# 第三阶段:设置最终的运行环境
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# 效果展示
## 设置Token页面
![token](./img/token.png)
## 获取目录地址(仅支持备份盘)
![dir](./img/dir.png)
## 批量修改页面
![batch](./img/batch.png)

Expand All @@ -28,5 +30,5 @@ docker run -d -p 9010:9010 -v /etc/aliyun:/etc/aliyun lwydyby/aliyun_tool
## 参数说明

- 目录地址: 要修改的阿里云盘目录地址,可以通过阿里云盘web端获取到
- 匹配格式: 用`$`符号标注出集号,比如文件名称为01.mp4,则匹配格式为$01$.mp4,提示: 可以通过填充按钮获取到文件的原名称,可能第一次获取会失败再试一次就好(是个bug但是懒得修了)
- 匹配格式: 用`$`符号标注出集号,比如文件名称为01.mp4,则匹配格式为$01$.mp4,提示: 可以通过填充按钮获取到文件的原名称
- 文件前缀: 修改后的文件名称前缀,比如原文件名称为01.mp4,文件前缀输入庆余年,则修改结果为庆余年E01.mp4
6 changes: 3 additions & 3 deletions api/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func GetFiles(ctx context.Context, fileId string, driverType string) ([]File, er
marker = ""
}
data := Json{
"drive_id": getDriveID(driverType),
"drive_id": GetDriveID(driverType),
"limit": 200,
"marker": marker,
"order_by": "created_at",
Expand Down Expand Up @@ -104,7 +104,7 @@ func Rename(name string, f File) error {
return err
}

func getDriveID(driveType string) string {
func GetDriveID(driveType string) string {
if config.C().DriveType == driveType && config.C().DriveID != "" {
return config.C().DriveID
}
Expand All @@ -116,7 +116,7 @@ func getDriveID(driveType string) string {
if err != nil {
panic(err)
}
config.C().DriveID = utils.Json.Get(res, config.C().DriveType+"_drive_id").ToString()
config.C().DriveID = utils.Json.Get(res, driveType+"_drive_id").ToString()
config.C().DriveType = driveType
config.SaveYaml()
return config.C().DriveID
Expand Down
76 changes: 75 additions & 1 deletion front/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
import {Button, Input, Tabs, Toast} from '@arco-design/mobile-react';
import {Button, Form, Input, Radio, Tabs, Toast} from '@arco-design/mobile-react';
import '@arco-design/mobile-react/esm/style';
import React, {useState} from "react";
import backend from "./backend.tsx";

const tabData = [
{title: 'token设置'},
{title: '模糊寻找目录'},
{title: '批量重命名'},
];

const rootOption =
[
{label: '备份盘', value: 'backup'},
{label: '资源库', value: 'resource',disabled: true},
]

function App() {
const [token, setToken] = React.useState('');
const [dir, setDir] = React.useState('');
const [deviceType, setDeviceType] = React.useState('backup');
const [url, setUrl] = React.useState('');
const [name, setName] = React.useState('');
const [prefix, setPrefix] = React.useState('');
const [tokenLoading, setTokenLoading] = useState(false);
const [nameLoading, setNameLoading] = useState(false);
const [submitLoading, setSubmitLoading] = useState(false);
const [urlVisbile, setUrlVisbile] = useState(false);
const [dirLoading, setDirLoading] = useState(false);
const handleOpenToken = () => {
window.open("https://alist.nn.ci/tool/aliyundrive/request.html", "_blank")
}
const handleGetDirUrl = async () => {
setDirLoading(true);
try {
const response = await fetch(backend + `/v1/dir`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
dir: dir,
device_type: deviceType,
}),
});
if (response.ok) {
const data = await response.json();
setUrl(data.url)
setUrlVisbile(true)
Toast.toast('请求成功');
// 处理你的数据
} else {
throw new Error('Something went wrong on api server!');
}
} catch (error) {
Toast.toast('请求失败,请重试');
console.error('Error occurred:', error);
} finally {
setDirLoading(false); // 关闭加载状态
}
}
const handleGetName = async () => {
setNameLoading(true);
try {
Expand Down Expand Up @@ -128,6 +168,40 @@ function App() {
<Button needActive loading={tokenLoading} onClick={handleSaveToken}>保存Token</Button>
</div>
</div>
<div className="demo-tab-content">
<Form layout={"vertical"}>
<Form.Item field="dir" label="目录名称" required>
<Input
value={dir}
onInput={(_, value) => setDir(value)}
onChange={(_, value) => setDir(value)}
placeholder="请输入目录名称,如果是多级目录则用/分隔,如:剧集/庆余年"
clearable
onClear={() => {
setDir('');
}}
border="none"
clearShowType='always'
/>
</Form.Item>
<Form.Item field="root" label="根目录(资源库api不支持查询)" required>
<Radio.Group options={rootOption} defaultValue={deviceType} onChange={value => {
if (typeof value === 'number') {
setDeviceType(value.toString());
} else {
setDeviceType(value);
}
}}/>
</Form.Item>
</Form>
<div style={{display: 'flex', justifyContent: 'space-around'}}>
<Button type="default" needActive onClick={handleGetDirUrl}
loading={dirLoading}>获取目录地址</Button>
</div>
<div>
{urlVisbile && <p>目录地址为: {url}</p>}
</div>
</div>
<div className="demo-tab-content">
<Input
value={url}
Expand Down
2 changes: 1 addition & 1 deletion front/src/backend.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const backend = "http://xxxxx:9010"
const backend = "http://xxxxxx:9010"

export default backend
Loading

0 comments on commit 272ce20

Please sign in to comment.