Skip to content

Commit

Permalink
feat: 文件支持远程/合并(后端 > 2.14.146)
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 11, 2024
1 parent e436a6b commit 65bd3ac
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 71 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.38",
"version": "2.14.39",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
98 changes: 37 additions & 61 deletions src/components/FileListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
<div class="sub-item-content">
<div class="sub-item-title-wrapper">

<h3 style="color: var(--primary-text-color); font-size: 16px; position: relative; top: 8px;">
<h3 v-if="!isSimpleMode" class="sub-item-title">
{{ displayName || name }}
</h3>
<h3 v-else style="color: var(--primary-text-color); font-size: 16px">
{{ displayName || name }}
</h3>

Expand Down Expand Up @@ -73,7 +76,37 @@
</button>
</div>
</div>

<template v-if="!isSimpleMode">
<p v-if="type === 'sub'" class="sub-item-detail">
<template v-if="typeof flow === 'string'">
<span>
{{ flow }}
</span>
</template>
<template v-else>
<span>
{{ flow.firstLine }}

Check failure on line 88 in src/components/FileListItem.vue

View workflow job for this annotation

GitHub Actions / build

Property 'firstLine' does not exist on type 'never'.
</span>
<span> {{ flow.secondLine }} </span>

Check failure on line 90 in src/components/FileListItem.vue

View workflow job for this annotation

GitHub Actions / build

Property 'secondLine' does not exist on type 'never'.
</template>
</p>
</template>

<template v-else>
<p class="sub-item-detail-isSimple">
<template v-if="typeof flow === 'string'">
<span style="font-weight: normal">
{{ flow }}
</span>
</template>
<template v-else>
<span style="font-weight: normal">
{{ flow.firstLine }} &nbsp;

Check failure on line 104 in src/components/FileListItem.vue

View workflow job for this annotation

GitHub Actions / build

Property 'firstLine' does not exist on type 'never'.
</span>
<span style="font-weight: normal"> {{ flow.secondLine }} </span>

Check failure on line 106 in src/components/FileListItem.vue

View workflow job for this annotation

GitHub Actions / build

Property 'secondLine' does not exist on type 'never'.
</template>
</p>
</template>
</div>
</div>
<!-- 加入判断 开启拖动不显示 -->
Expand Down Expand Up @@ -222,65 +255,8 @@
});
const flow = computed(() => {
if (props.type === 'sub') {
const urlList = Object.keys(flows.value);
if (props.sub.source === 'local') return t('subPage.subItem.local');
if (isFlowFetching.value && !urlList.includes(props.sub.url))
return t('subPage.subItem.loading');
const target = toRaw(flows.value[props.sub.url]);
if (!target) {
return {
firstLine: t('subPage.subItem.noRecord'),
secondLine: ``,
};
}
if (target.status === 'success') {
const {
expires,
total,
usage: { upload, download },
} = target.data;
let secondLine: string;
if (isSimpleMode.value) {
secondLine = !expires
? ''
: `${dayjs.unix(expires).format('YYYY-MM-DD')}`;
return {
firstLine: `${getString(upload + download, total, 'B')}`,
secondLine,
};
} else {
secondLine = !expires
? t('subPage.subItem.noExpiresInfo')
: `${t('subPage.subItem.expires')}:${dayjs
.unix(expires)
.format('YYYY-MM-DD')}`;
return {
firstLine: `${t('subPage.subItem.flow')}:${getString(
upload + download,
total,
'B'
)}`,
secondLine,
};
}
} else if (target?.status === 'failed') {
if (target.error.code === 'NO_FLOW_INFO') {
return {
firstLine: t('subPage.subItem.noFlowInfo'),
secondLine: ``,
};
} else {
return {
firstLine: `${target.error?.type}`,
secondLine: `${target.error?.message}`,
};
}
}
}
if (props.file.source === 'remote') return t('filePage.source.remote');
return t('filePage.source.local');
});
const closePreview = () => {
Expand Down
17 changes: 15 additions & 2 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export default {
content: {
placeholder: 'The content of the file'
},
url: {
label: 'URL',
placeholder: 'URL (please separate multiple urls with a new line)',
isEmpty: 'URL cannot be empty',
isIllegal: 'Invalid URL',
},
copyNotify: {
succeed: 'Successfully copied link!\nIf you use it internally, just {path}',
failed: 'Failed to copy file link!\n{e}',
Expand All @@ -77,6 +83,13 @@ export default {
desc: 'After adding you can enjoy the love of YM Peng',
btn: 'Create File Now',
},
source: {
local: 'Local',
remote: 'Remote',
},
ignoreFailedRemoteFile: {
label: 'Ignore failed remote file(s)'
},
},
// subscription management page
subPage: {
Expand Down Expand Up @@ -120,7 +133,7 @@ export default {
},
},
copyNotify: {
succeed: 'Successfully copied link!\nYou can paste in Proxy Tool now!',
succeed: 'Successfully copied link!',
failed: 'Failed to copy subscription link!\n{e}',
},
copyConfigNotify: {
Expand Down Expand Up @@ -214,7 +227,7 @@ export default {
ua: {
label: 'User-Agent',
placeholder:
'The User-Agent for downloading the original subscription',
'The User-Agent for downloading resource(s)',
},
},
commonOptions: {
Expand Down
17 changes: 15 additions & 2 deletions src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export default {
content: {
placeholder: '填入文件内容'
},
url: {
label: '链接',
placeholder: '链接(多个链接请换行)',
isEmpty: '链接不能为空',
isIllegal: '链接格式非法',
},
copyNotify: {
succeed: '复制文件链接成功\n如果你只在内部使用, 仅需 {path}',
failed: '复制文件链接失败\n{e}',
Expand All @@ -77,6 +83,13 @@ export default {
desc: '添加后开始使用文件',
btn: '立即添加',
},
source: {
local: '本地',
remote: '远程',
},
ignoreFailedRemoteFile: {
label: '忽略失败的远程文件'
},
},
// 订阅管理页
subPage: {
Expand Down Expand Up @@ -213,7 +226,7 @@ export default {
},
ua: {
label: 'User-Agent',
placeholder: '下载订阅使用的 UA,不填使用默认',
placeholder: '下载时使用的 UA,不填使用默认',
},
},
commonOptions: {
Expand Down Expand Up @@ -497,7 +510,7 @@ export default {
},
},
copyNotify: {
succeed: '复制 Gist 链接成功\n可以前往代理工具使用咯~',
succeed: '复制 Gist 链接成功',
failed: '复制 Gist 链接失败\n{e}',
},
addArtForm: {
Expand Down
104 changes: 99 additions & 5 deletions src/views/FileEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,49 @@
type="text"
/>
</nut-form-item>
<nut-form-item
required
:label="$t(`editorPage.subConfig.basic.source.label`)"
prop="source"
>
<div class="radio-wrapper">
<nut-radiogroup direction="horizontal" v-model="form.source">
<nut-radio shape="button" label="remote"
>{{ $t(`filePage.source.remote`) }}
</nut-radio>
<nut-radio shape="button" label="local"
>{{ $t(`filePage.source.local`) }}
</nut-radio>
</nut-radiogroup>
</div>
</nut-form-item>
<nut-form-item
required
v-if="form.source === 'remote'"
:label="$t(`editorPage.subConfig.basic.url.label`)"
prop="url"
:rules="[
{
required: true,
message: $t(`filePage.url.isEmpty`),
},
{
validator: urlValidator,
message: $t(`filePage.url.isIllegal`),
},
]"
>
<nut-textarea
class="textarea-wrapper"
@blur="customerBlurValidate('url')"
v-model="form.url"
:autosize="{ maxHeight: 110, minHeight: 50 }"
:placeholder="$t(`filePage.url.placeholder`)"
type="text"
/>
</nut-form-item>
<nut-form-item
v-else-if="form.source === 'local'"
:label="undefined"
prop="content"
>
Expand All @@ -68,11 +110,47 @@
type="text"
/>
</nut-form-item>
<!-- ua -->
<nut-form-item
:label="$t(`editorPage.subConfig.basic.ua.label`)"
prop="ua"
v-if="form.source === 'remote'"
>
<input
class="nut-input-text"
v-model.trim="form.ua"
:placeholder="$t(`editorPage.subConfig.basic.ua.placeholder`)"
type="text"
/>
</nut-form-item>





<nut-form-item
:label="$t(`editorPage.subConfig.basic.source.mergeSources`)"
prop="mergeSources"
>
<div class="radio-wrapper">
<nut-radiogroup direction="horizontal" v-model="form.mergeSources">
<nut-radio shape="button" label=""
>{{ $t(`editorPage.subConfig.basic.source.noMerge`) }}
</nut-radio>
<nut-radio shape="button" label="localFirst"
>{{ $t(`editorPage.subConfig.basic.source.localFirst`) }}
</nut-radio>
<nut-radio shape="button" label="remoteFirst"
>{{ $t(`editorPage.subConfig.basic.source.remoteFirst`) }}
</nut-radio>
</nut-radiogroup>
</div>
</nut-form-item>
<nut-form-item
:label="$t(`filePage.ignoreFailedRemoteFile.label`)"
prop="ignoreFailedRemoteFile"
class="ignore-failed-wrapper"
>
<div class="swtich-wrapper">
<nut-switch v-model="form.ignoreFailedRemoteFile"/>
</div>
</nut-form-item>
</nut-form>
</div>
<ActionBlock
Expand Down Expand Up @@ -163,6 +241,7 @@
name: '',
displayName: '',
icon: '',
source: 'local',
process: [],
});
provide('form', form);
Expand All @@ -185,8 +264,12 @@
form.name = sourceData.name;
form.displayName = sourceData.displayName || sourceData['display-name'];
form.icon = sourceData.icon;
form.source = sourceData.source || 'local';
form.url = sourceData.url;
form.ua = sourceData.ua;
form.mergeSources = sourceData.mergeSources;
form.content = sourceData.content;
form.ignoreFailedRemoteFile = sourceData.ignoreFailedRemoteFile;
const newProcess = JSON.parse(JSON.stringify(sourceData.process));
form.process = newProcess;
if (sourceData.process.length > 0) {
Expand Down Expand Up @@ -344,6 +427,17 @@
});
};
// url 格式验证器
const urlValidator = (val: string): Promise<boolean> => {
return new Promise(resolve => {
if (/\n/.test(val)) {
resolve(val.split(/[\r\n]+/).map(i => i.trim()).filter(i => i.length).every(i => /^(http|https):\/\/\S+$/.test(i)))
} else {
resolve(/^(http|https):\/\/\S+$/.test(val));
}
});
};
// 失去焦点触发验证
const customerBlurValidate = (prop: string) => {
ruleForm.value.validate(prop);
Expand Down

0 comments on commit 65bd3ac

Please sign in to comment.