-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Button123 component and integrate with provider
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
- 🎨 支持多个网盘平台 | ||
- 阿里云盘 | ||
- 夸克云盘 | ||
- 123云盘 | ||
- 移动云盘(新个人云) | ||
|
||
## 📺剧集模式 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<template> | ||
<button | ||
class="inline-block h-38px flex items-center justify-center gap-x-1 ws-nowrap rd-full bg-#597dfc px-4 py-2 text-white transition" | ||
mr-22px | ||
hover="op-80" | ||
> | ||
<i class="i-carbon:batch-job text-16px" /> | ||
<span class="text-14px font-medium">重命名</span> | ||
</button> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import type { Provider, Resource } from '~/types' | ||
import ButtonComponent from '~/components/Button123.vue' | ||
|
||
function getExt(fileName: string) { | ||
const i = fileName.lastIndexOf('.') | ||
return i > -1 ? fileName.slice(i + 1) : '' | ||
} | ||
|
||
function getParentId() { | ||
const u = new URLSearchParams(location.search) | ||
const path = u.get('homeFilePath') || '0' | ||
const groups = path.split(',') | ||
const lastGroup = groups[groups.length - 1] | ||
return lastGroup | ||
} | ||
|
||
async function getFileListOfCurrentDir(parentId = getParentId()) { | ||
const listApi = new URL('https://www.123pan.com/b/api/file/list/new?driveId=0&limit=100&next=0&orderBy=file_name&orderDirection=asc&trashed=false&SearchData=&OnlyLookAbnormalFile=0&event=homeListFile&operateType=4&inDirectSpace=false') | ||
listApi.searchParams.set('parentFileId', parentId) | ||
const result: Resource[] = [] | ||
let page = 1 | ||
let next = true | ||
|
||
while (next) { | ||
listApi.searchParams.set('Page', String(page++)) | ||
const { data: { InfoList, Next } } = await get(listApi) | ||
result.push(...InfoList.map((x: any) => ({ | ||
drive_id: 'whocare', | ||
file_id: x.FileId, | ||
name: x.FileName, | ||
parent_file_id: x.ParentFileId, | ||
file_extension: getExt(x.FileName), | ||
mime_type: 'whocare', | ||
type: x.type === 1 ? 'folder' : 'file', | ||
}))) | ||
next = Next !== '-1' | ||
} | ||
|
||
return result | ||
} | ||
|
||
const headers: Record<string, string> = {} | ||
|
||
export function setRequestHeader(key: string, value: string) { | ||
if (key.toLowerCase() === 'authorization') | ||
headers.authorization = value | ||
} | ||
|
||
function post(api: URL | string, payload: object) { | ||
return fetch(api, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
...headers, | ||
}, | ||
credentials: 'include', | ||
body: JSON.stringify(payload), | ||
}).then((res) => { | ||
if (res.ok) | ||
return res.json() | ||
else | ||
return Promise.reject(new Error('network error')) | ||
}) | ||
} | ||
|
||
function get(api: URL | string) { | ||
return fetch(api, { | ||
method: 'GET', | ||
headers: { | ||
...headers, | ||
}, | ||
credentials: 'include', | ||
}).then((res) => { | ||
if (res.ok) | ||
return res.json() | ||
else | ||
return Promise.reject(new Error('network error')) | ||
}) | ||
} | ||
|
||
async function renameOne(resource: Resource, newName: string) { | ||
return post('https://www.123pan.com/b/api/file/rename', { | ||
driveId: 0, | ||
fileId: resource.file_id, | ||
fileName: newName, | ||
duplicate: 1, | ||
event: 'fileRename', | ||
operatePlace: 2, | ||
RequestSource: null, | ||
}) | ||
} | ||
|
||
function shouldShowEntry(url: string) { | ||
return new URL(url).pathname === '/' | ||
} | ||
|
||
function getContainer() { | ||
return { | ||
el: document.querySelector('#app .homeClass > div:nth-child(1)'), | ||
style: '', | ||
front: true, | ||
} | ||
} | ||
|
||
const provider: Provider = { | ||
DRIVE_NAME: '123云盘', | ||
HOSTS: ['www.123pan.com'], | ||
ButtonComponent, | ||
shouldShowEntry, | ||
getContainer, | ||
renameOne, | ||
setRequestHeader, | ||
getFileListOfCurrentDir, | ||
} | ||
|
||
export default provider |