Skip to content

Commit

Permalink
feat: add Button123 component and integrate with provider
Browse files Browse the repository at this point in the history
  • Loading branch information
a1mersnow committed Jan 4, 2025
1 parent 7a5a3ed commit 1e652e1
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- 🎨 支持多个网盘平台
- 阿里云盘
- 夸克云盘
- 123云盘
- 移动云盘(新个人云)

## 📺剧集模式
Expand Down
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
Button123: typeof import('./src/components/Button123.vue')['default']
ButtonAliyun: typeof import('./src/components/ButtonAliyun.vue')['default']
ButtonCmcc: typeof import('./src/components/ButtonCmcc.vue')['default']
ButtonQuark: typeof import('./src/components/ButtonQuark.vue')['default']
Expand Down
10 changes: 10 additions & 0 deletions src/components/Button123.vue
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>
116 changes: 116 additions & 0 deletions src/providers/123.ts
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

0 comments on commit 1e652e1

Please sign in to comment.