Skip to content

Commit

Permalink
Merge pull request #9 from Rovniced/ef2
Browse files Browse the repository at this point in the history
支持导出为ef2格式
  • Loading branch information
Yingyya authored Aug 13, 2024
2 parents 339a71d + cb9cee3 commit 39933d2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
24 changes: 20 additions & 4 deletions src/pages/Parsed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {useRoute, useRouter} from 'vue-router';
import {useWorker} from '@/hooks/useWorker';
import {renderSize} from '@/utils/render-size';
import {sendToRPC} from '@/utils/send-to-rpc';
import {packageDownloadLinks} from '@/utils/package-download-links';
import { package2IDMLinks, packageDownloadLinks } from '@/utils/package-download-links';
import {getFileList} from '@/services/parse';
import {dealFileList} from '@/utils/deal-file-list';
import type {ParsedFile, ShareInfo, TreeFileInfo, WorkerRequestBody, WorkerResponse} from '@/types';
Expand Down Expand Up @@ -47,7 +47,7 @@ const userRef = storeToRefs(userStore);
const rpcRef = userRef.rpc;
const exportFormat = userRef.exportFormat;
const downloadType = ref<{
code: 'web' | 'jsonrpc' | ''
code: 'web' | 'jsonrpc' | 'idm' |''
}>({
code: ''
});
Expand Down Expand Up @@ -190,7 +190,12 @@ const onWorkerMessage = async (m: WorkerResponse) => {
await packageDownloadLinks(results, userRef.exportFormat.value);
stop();
return;
} else if (downloadType.value.code === 'idm') {
await package2IDMLinks(results);
stop();
return;
}
stop();
return;
}
Expand All @@ -214,7 +219,8 @@ const onWorkerMessage = async (m: WorkerResponse) => {
// Web
results.push({
filename: m!!.body!!.filename,
link: m!!.body!!.dlink
link: m!!.body!!.dlink,
ua: m!!.body!!.ua
});
}
if (m.type === 'error') {
Expand Down Expand Up @@ -301,7 +307,7 @@ worker.setCallback(onWorkerMessage);
<div class="field col">
<label for="type">下载方式</label>
<Dropdown v-model="downloadType" :disabled="blocked"
:options="[{name: 'Web', code: 'web'}, {name: 'JSON RPC', code: 'jsonrpc'}]"
:options="[{name: 'Web', code: 'web'}, {name: 'JSON RPC', code: 'jsonrpc'},{name: 'IDM 下载', code: 'idm'}]"
optionLabel="name" placeholder="选择下载方式"/>
</div>
</div>
Expand Down Expand Up @@ -359,6 +365,16 @@ worker.setCallback(onWorkerMessage);
<strong>保存的文件夹和您分享出的文件的根目录有关,和您网盘的存储路径无关。</strong>
</p>
</template>
<template v-if="downloadType.code === 'idm'">
<Divider align="left" type="solid">
<b>IDM 下载导入说明</b>
</Divider>
<Divider></Divider>
<p>压缩包内会生成一个 ef2 格式的文件,仅可在<strong>电脑版IDM</strong>中使用。<br>
打开IDM,点击右上角<strong>任务</strong>——<strong>导入</strong>——<strong>从"IDM导出文件"导入</strong><br>
此功能会自动帮你设置UA,无需在IDM设置中更改。<br>
</p>
</template>
</Fieldset>
<Fieldset legend="准备下载">
<ProgressBar :mode="starting && progress === 0 ? 'indeterminate' : 'determinate'"
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type TreeFileInfo = {
export type ParsedFile = {
filename: string;
link: string;
ua: string;
};

export type ParsedFileResult = {
Expand Down
39 changes: 35 additions & 4 deletions src/utils/package-download-links.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import JSZip from 'jszip';
import {useMessage} from '@/hooks/useMessage';
import { useMessage } from '@/hooks/useMessage';
import FileSaver from 'file-saver';
import type {ParsedFile} from '@/types';
import type { ParsedFile } from '@/types';
import { useSystemConfigStore } from '@/store';

function getREADME() {
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function packageDownloadLinks(results: ParsedFile[], format: string
type: 'blob',
compression: 'DEFLATE',
compressionOptions: {
level: 9,
level: 9
}
});
FileSaver.saveAs(blob, 'F4Pan-' + Date.now() + '.zip');
Expand All @@ -45,4 +45,35 @@ export async function packageDownloadLinks(results: ParsedFile[], format: string
message.error('打包失败,请重新尝试或使用 JSON RPC 下载。');
}
return false;
}
}

/**
* IDM格式打包下载
* @param results
*/
export async function package2IDMLinks(results: ParsedFile[]) {
const zip = new JSZip();
const message = useMessage();
zip.file('说明.txt', getREADME());
// https://github.com/MotooriKashin/ef2 第三方的ef2工具支持指定文件名,官方的不支持,但是不会影响读取。
const content = results.map(v => {
return `<\r\n${v.link}\r\nUser-Agent: ${v.ua}\r\nfilename: ${v.filename}\r\n>`;
}).join('\r\n');
zip.file('任务.ef2', content + '\r\n');
try {
const blob = await zip.generateAsync({
type: 'blob',
compression: 'DEFLATE',
compressionOptions: {
level: 9
}
});
FileSaver.saveAs(blob, 'F4Pan-' + Date.now() + '.zip');
message.success('打包成功!正在下载……');
return true;
} catch (e) {
console.error(e);
message.error('打包失败,请重新尝试或使用 JSON RPC 下载。');
}
return false;
}

0 comments on commit 39933d2

Please sign in to comment.