bot
commited on
Commit
·
df44ba9
1
Parent(s):
aa547c1
新增离线功能
Browse files- main.py +7 -0
- templates/index.html +168 -5
main.py
CHANGED
@@ -169,6 +169,13 @@ async def get_file_info(file_id: str):
|
|
169 |
return await THUNDERX_CLIENT.get_download_url(file_id)
|
170 |
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
@api_router.post(
|
173 |
"/emptytrash", summary="清空回收站", description="清空回收站【慎用】", tags=["文件"]
|
174 |
)
|
|
|
169 |
return await THUNDERX_CLIENT.get_download_url(file_id)
|
170 |
|
171 |
|
172 |
+
@api_router.delete(
|
173 |
+
"/files/{file_id}", summary="删除文件", description="删除文件", tags=["文件"]
|
174 |
+
)
|
175 |
+
async def delete_file_info(file_id: str):
|
176 |
+
return await THUNDERX_CLIENT.delete_forever([file_id])
|
177 |
+
|
178 |
+
|
179 |
@api_router.post(
|
180 |
"/emptytrash", summary="清空回收站", description="清空回收站【慎用】", tags=["文件"]
|
181 |
)
|
templates/index.html
CHANGED
@@ -845,6 +845,7 @@
|
|
845 |
</Navbar.Brand>
|
846 |
</div>
|
847 |
<div className="d-flex">
|
|
|
848 |
<Tasks />
|
849 |
<LocalTasks />
|
850 |
<Button
|
@@ -1031,6 +1032,15 @@
|
|
1031 |
/>)
|
1032 |
}
|
1033 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1034 |
|
1035 |
<Icon
|
1036 |
icon="share-variant"
|
@@ -1069,7 +1079,7 @@
|
|
1069 |
mutationKey: ["create_share"],
|
1070 |
mutationFn: async (fileinfo) => {
|
1071 |
showLoading();
|
1072 |
-
var url = 'file_batch_share?need_password=false&expiration_days=-1';
|
1073 |
return await axios.post(url, [fileinfo.id], {
|
1074 |
headers: {
|
1075 |
'Authorization': authorization,
|
@@ -1084,6 +1094,26 @@
|
|
1084 |
hideLoading();
|
1085 |
}
|
1086 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1087 |
|
1088 |
const { data: linksData, mutateAsync: filesMutation, error: linksError, isPending: linksLoading } = useMutation({
|
1089 |
mutationKey: ["get-files", pageToken],
|
@@ -1137,14 +1167,18 @@
|
|
1137 |
}
|
1138 |
}, [fileData]);
|
1139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1140 |
useEffect(() => {
|
1141 |
if (shareData) {
|
1142 |
layer.alert(shareData.data.share_url);
|
1143 |
}
|
1144 |
}, [shareData]);
|
1145 |
|
1146 |
-
|
1147 |
-
|
1148 |
const handleSearchClick = () => {
|
1149 |
setSearch(keyword)
|
1150 |
};
|
@@ -1311,8 +1345,6 @@
|
|
1311 |
}, [linksData]);
|
1312 |
|
1313 |
|
1314 |
-
|
1315 |
-
|
1316 |
const forceUpdate = () => {
|
1317 |
setReload((pre) => !pre);
|
1318 |
};
|
@@ -1366,7 +1398,138 @@
|
|
1366 |
);
|
1367 |
};
|
1368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1370 |
const Tasks = () => {
|
1371 |
const [show, setShow] = useState(false);
|
1372 |
const handleClose = () => setShow(false);
|
|
|
845 |
</Navbar.Brand>
|
846 |
</div>
|
847 |
<div className="d-flex">
|
848 |
+
<Offline />
|
849 |
<Tasks />
|
850 |
<LocalTasks />
|
851 |
<Button
|
|
|
1032 |
/>)
|
1033 |
}
|
1034 |
|
1035 |
+
<Icon
|
1036 |
+
icon="delete"
|
1037 |
+
size="6"
|
1038 |
+
className="me-2"
|
1039 |
+
onClick={ async () => {
|
1040 |
+
let data = { "id": row.id }
|
1041 |
+
await deleteMutation(data);
|
1042 |
+
} }
|
1043 |
+
/>
|
1044 |
|
1045 |
<Icon
|
1046 |
icon="share-variant"
|
|
|
1079 |
mutationKey: ["create_share"],
|
1080 |
mutationFn: async (fileinfo) => {
|
1081 |
showLoading();
|
1082 |
+
var url = '/file_batch_share?need_password=false&expiration_days=-1';
|
1083 |
return await axios.post(url, [fileinfo.id], {
|
1084 |
headers: {
|
1085 |
'Authorization': authorization,
|
|
|
1094 |
hideLoading();
|
1095 |
}
|
1096 |
})
|
1097 |
+
const { data: deleteData, mutateAsync: deleteMutation } = useMutation({
|
1098 |
+
mutationKey: ["delete_file"],
|
1099 |
+
mutationFn: async (fileinfo) => {
|
1100 |
+
showLoading();
|
1101 |
+
var url = '/files/' + fileinfo.id;
|
1102 |
+
return await axios.delete(url, {
|
1103 |
+
headers: {
|
1104 |
+
'Authorization': authorization,
|
1105 |
+
'Content-Type': 'application/json'
|
1106 |
+
},
|
1107 |
+
})
|
1108 |
+
},
|
1109 |
+
onSuccess: async (data, variables, context) => {
|
1110 |
+
hideLoading();
|
1111 |
+
forceUpdate();
|
1112 |
+
},
|
1113 |
+
onError: () => {
|
1114 |
+
hideLoading();
|
1115 |
+
}
|
1116 |
+
})
|
1117 |
|
1118 |
const { data: linksData, mutateAsync: filesMutation, error: linksError, isPending: linksLoading } = useMutation({
|
1119 |
mutationKey: ["get-files", pageToken],
|
|
|
1167 |
}
|
1168 |
}, [fileData]);
|
1169 |
|
1170 |
+
useEffect(() => {
|
1171 |
+
if (deleteData) {
|
1172 |
+
layer.msg("删除完成,请刷新查看结果");
|
1173 |
+
}
|
1174 |
+
}, [deleteData]);
|
1175 |
+
|
1176 |
useEffect(() => {
|
1177 |
if (shareData) {
|
1178 |
layer.alert(shareData.data.share_url);
|
1179 |
}
|
1180 |
}, [shareData]);
|
1181 |
|
|
|
|
|
1182 |
const handleSearchClick = () => {
|
1183 |
setSearch(keyword)
|
1184 |
};
|
|
|
1345 |
}, [linksData]);
|
1346 |
|
1347 |
|
|
|
|
|
1348 |
const forceUpdate = () => {
|
1349 |
setReload((pre) => !pre);
|
1350 |
};
|
|
|
1398 |
);
|
1399 |
};
|
1400 |
|
1401 |
+
const Offline = () => {
|
1402 |
+
const [selectedOption, setSelectedOption] = useState(1);
|
1403 |
+
const handleOptionChange = (event) => {
|
1404 |
+
setSelectedOption(event.target.value);
|
1405 |
+
};
|
1406 |
+
|
1407 |
+
const [linkValue, setLinkValue] = useState('');
|
1408 |
+
const handleLinkChange = (event) => {
|
1409 |
+
setLinkValue(event.target.value);
|
1410 |
+
};
|
1411 |
+
|
1412 |
+
const [show, setShow] = useState(false);
|
1413 |
+
const handleClose = () => setShow(false);
|
1414 |
+
const handleShow = () => setShow(true);
|
1415 |
+
const setting = STORE.getState().settings;
|
1416 |
+
const authorization = 'Bearer ' + setting.secret_token;
|
1417 |
+
|
1418 |
+
const { data: taskData, mutateAsync: offlineMutation, error: taskError, isPending: taskLoading } = useMutation({
|
1419 |
+
mutationKey: ["offfline-files"],
|
1420 |
+
mutationFn: async (query) => {
|
1421 |
+
showLoading();
|
1422 |
+
var url = query.url;
|
1423 |
+
return await axios.post(url, query.data, {
|
1424 |
+
headers: {
|
1425 |
+
'Authorization': authorization,
|
1426 |
+
'Content-Type': 'application/json'
|
1427 |
+
},
|
1428 |
+
})
|
1429 |
+
},
|
1430 |
+
onSuccess: async (data, variables, context) => {
|
1431 |
+
hideLoading();
|
1432 |
+
},
|
1433 |
+
onError: () => {
|
1434 |
+
hideLoading();
|
1435 |
+
}
|
1436 |
+
})
|
1437 |
+
|
1438 |
+
useEffect(() => {
|
1439 |
+
if (taskData) {
|
1440 |
+
layer.msg("添加完成,刷新查看");
|
1441 |
+
}
|
1442 |
+
}, [taskData]);
|
1443 |
+
|
1444 |
|
1445 |
+
return (
|
1446 |
+
<div>
|
1447 |
+
<Button
|
1448 |
+
style={ {
|
1449 |
+
backgroundColor: "transparent",
|
1450 |
+
} }
|
1451 |
+
className="nav-link btn mr-1"
|
1452 |
+
onClick={ handleShow }
|
1453 |
+
children={
|
1454 |
+
<span>
|
1455 |
+
<Icon
|
1456 |
+
icon="plus"
|
1457 |
+
size="3"
|
1458 |
+
className="text-white"
|
1459 |
+
/>
|
1460 |
+
</span>
|
1461 |
+
}
|
1462 |
+
></Button>
|
1463 |
+
<Modal show={ show } onHide={ handleClose }>
|
1464 |
+
<Modal.Header closeButton>
|
1465 |
+
<Modal.Title>添加离线</Modal.Title>
|
1466 |
+
</Modal.Header>
|
1467 |
+
<Modal.Body>
|
1468 |
+
<Form>
|
1469 |
+
<Form.Group className="mb-3" controlId="exampleForm.ControlInput1">
|
1470 |
+
<Form.Label>链接类型</Form.Label>
|
1471 |
+
<div>
|
1472 |
+
<Form.Check
|
1473 |
+
inline
|
1474 |
+
label="磁力"
|
1475 |
+
name="offline_type"
|
1476 |
+
type="radio"
|
1477 |
+
value={ 1 }
|
1478 |
+
checked={ selectedOption == 1 }
|
1479 |
+
onChange={ handleOptionChange }
|
1480 |
+
/>
|
1481 |
+
<Form.Check
|
1482 |
+
inline
|
1483 |
+
label="分享"
|
1484 |
+
name="offline_type"
|
1485 |
+
type="radio"
|
1486 |
+
value={ 2 }
|
1487 |
+
checked={ selectedOption == 2 }
|
1488 |
+
onChange={ handleOptionChange }
|
1489 |
+
/>
|
1490 |
+
</div>
|
1491 |
+
</Form.Group>
|
1492 |
+
<Form.Group
|
1493 |
+
className="mb-3"
|
1494 |
+
controlId="exampleForm.ControlTextarea1"
|
1495 |
+
>
|
1496 |
+
<Form.Label>链接地址</Form.Label>
|
1497 |
+
<Form.Control as="textarea" value={ linkValue }
|
1498 |
+
onChange={ handleLinkChange } rows={ 3 } />
|
1499 |
+
</Form.Group>
|
1500 |
+
</Form>
|
1501 |
+
</Modal.Body>
|
1502 |
+
<Modal.Footer>
|
1503 |
+
<Button variant="secondary" onClick={ handleClose }>
|
1504 |
+
关闭
|
1505 |
+
</Button>
|
1506 |
+
<Button variant="primary" onClick={ async () => {
|
1507 |
+
var data = {};
|
1508 |
+
if (selectedOption == 1) {
|
1509 |
+
data = {
|
1510 |
+
url: "/offline",
|
1511 |
+
data: {
|
1512 |
+
"file_url": linkValue,
|
1513 |
+
"parent_id": "",
|
1514 |
+
"name": "",
|
1515 |
+
"additionalProp1": {}
|
1516 |
+
}
|
1517 |
+
}
|
1518 |
+
} else {
|
1519 |
+
data = {
|
1520 |
+
url: "/restore?share_id=" + linkValue,
|
1521 |
+
data: []
|
1522 |
+
}
|
1523 |
+
}
|
1524 |
+
await offlineMutation(data);
|
1525 |
+
} }>
|
1526 |
+
保存
|
1527 |
+
</Button>
|
1528 |
+
</Modal.Footer>
|
1529 |
+
</Modal>
|
1530 |
+
</div>
|
1531 |
+
);
|
1532 |
+
}
|
1533 |
const Tasks = () => {
|
1534 |
const [show, setShow] = useState(false);
|
1535 |
const handleClose = () => setShow(false);
|