Skip to content

Commit

Permalink
fix: fetch whole list
Browse files Browse the repository at this point in the history
  • Loading branch information
a1mersnow committed Nov 30, 2023
1 parent 56da2eb commit 1b38090
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ onUnmounted(() => {
/>
可将其填充到“剧名”
</div>

<div v-if="showList.length" class="ml-auto text-xs font-sans text-gray-600">
共 <span class="font-bold text-purple-600">{{ showList.length }}</span> 个文件
</div>
</div>
<ul
v-if="showList.length" class="grid grid-cols-[20px_auto_30px_minmax(200px,1fr)] items-center gap-x-2 gap-y-1 text-xs"
Expand Down
35 changes: 24 additions & 11 deletions src/utils/aliyun.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const listJsonMask = 'ext_marker,items(name,file_id,drive_id,type,size,created_at,updated_at,category,file_extension,parent_file_id,mime_type,starred,thumbnail,url,streams_info,content_hash,user_tags,user_meta,trashed,video_media_metadata,video_preview_metadata,sync_meta,sync_device_flag,sync_flag,punish_flag)'
const listJsonMask = 'next_marker,items(name,file_id,drive_id,type,size,created_at,updated_at,category,file_extension,parent_file_id,mime_type,starred,thumbnail,url,streams_info,content_hash,user_tags,user_meta,trashed,video_media_metadata,video_preview_metadata,sync_meta,sync_device_flag,sync_flag,punish_flag)'

// 接口调用太频繁会被拒
export const API_DELAY = 200

const PAGE_SIZE = 100

function getToken() {
const raw = window.localStorage.getItem('token')
if (!raw)
Expand All @@ -15,20 +17,31 @@ async function getDriveId() {
return location.pathname.startsWith('/drive/file/resource') ? res.resource_drive_id : res.backup_drive_id
}

const INITIAL_MARKER = 'INITIAL'
export async function getFileListOfCurrentDir(parentId = getParentId()) {
const listApi = new URL('https://api.aliyundrive.com/adrive/v3/file/list')
listApi.searchParams.append('jsonmask', listJsonMask)
const driveId = await getDriveId()
const res = await post(listApi, {
all: true,
drive_id: driveId,
fields: '*',
order_by: 'name',
order_direction: 'ASC',
parent_file_id: parentId,
url_expire_sec: 14400,
})
return res.items.filter((x: any) => !x.sync_device_flag) as Resource[]
const result = []
let marker = INITIAL_MARKER

while (marker) {
const { items, next_marker } = await post(listApi, {
all: true,
limit: PAGE_SIZE,
drive_id: driveId,
fields: '*',
order_by: 'name',
order_direction: 'ASC',
parent_file_id: parentId,
url_expire_sec: 14400,
marker: marker === INITIAL_MARKER ? '' : marker,
})
result.push(...items)
marker = next_marker
}

return result.filter((x: any) => !x.sync_device_flag) as Resource[]
}

async function rename(driveId: string, fileId: string, newName: string) {
Expand Down

0 comments on commit 1b38090

Please sign in to comment.