Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.34.0",
"version": "2.34.1",
"private": true,
"packageManager": "pnpm@11.0.9",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/components/ShareListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import {
formatShareTimestamp,
getShareEditPath,
getSharePublicUrl,
isShareLifetimeExpiration,
resolveShareDisplayIconState,
} from "@/utils/share";
import { normalizeTagArray } from "@/utils/shareTags";
Expand Down Expand Up @@ -218,6 +219,10 @@ const leftTime = computed(() => {
: t("sharePage.expired");
}

if (isShareLifetimeExpiration(props?.data)) {
return t("sharePage.createShare.unit.lifetime");
}

return props?.data?.exp
? dayjs(props?.data?.exp).diff(dayjs(), "second") > 0
? `${t("sharePage.leftTime")} ${dayjs(props?.data?.exp).diff(dayjs(), "day", true).toFixed(0)} ${t("sharePage.createShare.unit.day")}`
Expand Down
9 changes: 9 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ export default {
month: "Month",
season: "Season",
year: "Year",
lifetime: "Lifetime",
},
copyBtn: "Copy Link",
},
Expand Down Expand Up @@ -1263,6 +1264,14 @@ export default {
title: "Unable to verify backend version right now",
desc: "Check the current backend connection and try saving the exact expiration date and time again.",
},
lifetimeBackendRequired: {
title: "This backend does not support lifetime shares yet",
desc: "The current backend version is {currentVersion}. Upgrade to {minVersion} or later before saving a lifetime share.",
},
lifetimeBackendCheckFailed: {
title: "Unable to verify backend version right now",
desc: "Check the current backend connection and try saving the lifetime share again.",
},
failNotify: "Update share failed",
},
copyShare: {
Expand Down
11 changes: 10 additions & 1 deletion src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,8 @@ export default {
"day": "Дн.",
"month": "Мес.",
"season": "Квартал",
"year": "Год"
"year": "Год",
"lifetime": "Бессрочно"
},
"copyBtn": "Копировать ссылку"
},
Expand Down Expand Up @@ -1309,6 +1310,14 @@ export default {
"title": "В данный момент невозможно проверить версию бэкенда",
"desc": "Проверьте текущее подключение к бэкенду и попробуйте сохранить точную дату и время истечения снова."
},
"lifetimeBackendRequired": {
"title": "Этот бэкенд еще не поддерживает бессрочные ссылки",
"desc": "Текущая версия бэкенда: {currentVersion}. Обновитесь до версии {minVersion} или выше, чтобы сохранять бессрочные ссылки."
},
"lifetimeBackendCheckFailed": {
"title": "В данный момент невозможно проверить версию бэкенда",
"desc": "Проверьте текущее подключение к бэкенду и попробуйте сохранить бессрочную ссылку снова."
},
"failNotify": "Не удалось обновить ссылку для шеринга"
},
"copyShare": {
Expand Down
9 changes: 9 additions & 0 deletions src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ export default {
month: "月",
season: "季",
year: "年",
lifetime: "长期有效",
},
copyBtn: "复制链接",
},
Expand Down Expand Up @@ -1217,6 +1218,14 @@ export default {
title: "暂时无法验证后端版本",
desc: "请检查当前后端连接是否正常,然后重试保存指定到期日期时间。",
},
lifetimeBackendRequired: {
title: "当前后端暂不支持长期有效",
desc: "检测到后端版本为 {currentVersion},需要升级到 {minVersion} 或更高版本后,才能保存长期有效的分享。",
},
lifetimeBackendCheckFailed: {
title: "暂时无法验证后端版本",
desc: "请检查当前后端连接是否正常,然后重试保存长期有效的分享。",
},
failNotify: "更新分享失败",
},
copyShare: {
Expand Down
4 changes: 2 additions & 2 deletions src/types/store/subsStore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ interface Share {
mode?: 'duration' | 'datetime' | 'count' | null;
expiresIn?: string | null;
expiresValue?: string | null;
expiresUnit?: 'day' | 'month' | 'season' | 'year' | null;
expiresUnit?: 'day' | 'month' | 'season' | 'year' | 'lifetime' | null;
expiresAt?: number | null;
exp?: number | null;
count?: number | null;
Expand All @@ -138,7 +138,7 @@ interface ShareToken {
options?: {
expiresIn?: number | string | undefined;
expiresValue?: number | string | undefined;
expiresUnit?: 'day' | 'month' | 'season' | 'year' | undefined;
expiresUnit?: 'day' | 'month' | 'season' | 'year' | 'lifetime' | undefined;
exp?: number | string | null | undefined;
count?: number | string | undefined;
usedCount?: number | string | undefined;
Expand Down
40 changes: 34 additions & 6 deletions src/utils/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ export const isShareType = (value: unknown): value is 'sub' | 'col' | 'file' =>

export const SHARE_EDITOR_CREATE_ID = 'UNTITLED';
export const SHARE_EXPIRATION_DATETIME_BACKEND_VERSION = '2.22.6';
export const SHARE_EXPIRATION_LIFETIME_BACKEND_VERSION = '2.42.5';

export type ShareExpirationMode = 'duration' | 'datetime' | 'count';
export type ShareExpirationUnit = 'day' | 'month' | 'season' | 'year';
export type ShareExpirationUnit = 'day' | 'month' | 'season' | 'year' | 'lifetime';
// 长期有效不对应具体时长, 只有这些单位能换算成 expiresIn
export type ShareTimedExpirationUnit = Exclude<ShareExpirationUnit, 'lifetime'>;
export const SHARE_LIFETIME_EXPIRATION_UNIT = 'lifetime';

const DEFAULT_SHARE_EXPIRATION_MODE: ShareExpirationMode = 'duration';
const DEFAULT_SHARE_EXPIRATION_UNIT: ShareExpirationUnit = 'day';
const SHARE_DISPLAY_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH:mm';
const SHARE_DURATION_MS_UNIT_MAP: Record<ShareExpirationUnit, number> = {
const SHARE_DURATION_MS_UNIT_MAP: Record<ShareTimedExpirationUnit, number> = {
day: 24 * 60 * 60 * 1000,
month: 30 * 24 * 60 * 60 * 1000,
season: 90 * 24 * 60 * 60 * 1000,
Expand All @@ -29,12 +33,12 @@ const formatDurationValue = (value: number) => {

const parseMillisecondsDuration = (
durationMs: number,
): { value: number; unit: ShareExpirationUnit } | null => {
): { value: number; unit: ShareTimedExpirationUnit } | null => {
if (!Number.isFinite(durationMs) || durationMs <= 0) {
return null;
}

const exactUnits: ShareExpirationUnit[] = ['year', 'season', 'month', 'day'];
const exactUnits: ShareTimedExpirationUnit[] = ['year', 'season', 'month', 'day'];
for (const unit of exactUnits) {
const unitMs = SHARE_DURATION_MS_UNIT_MAP[unit];
if (Number.isInteger(durationMs / unitMs)) {
Expand Down Expand Up @@ -72,7 +76,18 @@ export const isShareExpirationMode = (value: unknown): value is ShareExpirationM
};

export const isShareExpirationUnit = (value: unknown): value is ShareExpirationUnit => {
return value === 'day' || value === 'month' || value === 'season' || value === 'year';
return value === 'day'
|| value === 'month'
|| value === 'season'
|| value === 'year'
|| value === SHARE_LIFETIME_EXPIRATION_UNIT;
};

export const isShareLifetimeExpiration = (share?: {
mode?: ShareExpirationMode | null;
expiresUnit?: string | null;
} | null) => {
return share?.mode === 'duration' && share?.expiresUnit === SHARE_LIFETIME_EXPIRATION_UNIT;
};

const getValidTimestamp = (value?: number | string | null) => {
Expand All @@ -95,6 +110,10 @@ export const supportsShareExpirationDatetime = (backendVersion?: string | null)
return semverGte(backendVersion, SHARE_EXPIRATION_DATETIME_BACKEND_VERSION);
};

export const supportsShareExpirationLifetime = (backendVersion?: string | null) => {
return semverGte(backendVersion, SHARE_EXPIRATION_LIFETIME_BACKEND_VERSION);
};

const createDefaultShareExpirationFormState = (): ShareExpirationFormState => {
return {
mode: DEFAULT_SHARE_EXPIRATION_MODE,
Expand Down Expand Up @@ -142,7 +161,7 @@ export const resolveShareDisplayIconState = ({
};
};

const parseShareDuration = (input: string): { value: number; unit: ShareExpirationUnit } | null => {
const parseShareDuration = (input: string): { value: number; unit: ShareTimedExpirationUnit } | null => {
if (!input) {
return null;
}
Expand Down Expand Up @@ -305,6 +324,15 @@ export const getShareExpirationFormState = ({
return getCountState(count);
}

if (isShareLifetimeExpiration({ mode: nextMode, expiresUnit })) {
return {
mode: 'duration',
expiresValue: '',
expiresUnit: SHARE_LIFETIME_EXPIRATION_UNIT,
exactDatetime: null,
};
}

const storedDurationState = getDurationStateFromStoredInput(expiresValue, expiresUnit);
if (storedDurationState) {
return storedDurationState;
Expand Down
62 changes: 58 additions & 4 deletions src/views/share/ShareEditorPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

<template v-if="isDurationExpirationMode">
<nut-form-item
v-if="!isLifetimeExpirationUnit"
:label="$t(`sharePage.createShare.expiresValue.label`)"
prop="expiresValue"
required
Expand Down Expand Up @@ -475,9 +476,13 @@ import {
parseShareEditorRouteIdentity,
resolveShareDisplayIconState,
SHARE_EXPIRATION_DATETIME_BACKEND_VERSION,
SHARE_EXPIRATION_LIFETIME_BACKEND_VERSION,
SHARE_LIFETIME_EXPIRATION_UNIT,
supportsShareExpirationDatetime,
supportsShareExpirationLifetime,
type ShareExpirationMode,
type ShareExpirationUnit,
type ShareTimedExpirationUnit,
} from "@/utils/share";
import { normalizeTagArray, stringifyTagInput } from "@/utils/shareTags";
import { normalizeOptionalImageFit, resolveImageFit, type ImageFit } from "@/utils/iconFit";
Expand Down Expand Up @@ -629,6 +634,7 @@ const submitButtonLabel = computed(() => {
const isExactExpirationMode = computed(() => form.expirationMode === "datetime");
const isDurationExpirationMode = computed(() => form.expirationMode === "duration");
const isCountExpirationMode = computed(() => form.expirationMode === "count");
const isLifetimeExpirationUnit = computed(() => form.expiresUnit === SHARE_LIFETIME_EXPIRATION_UNIT);
const shouldShowShareUrlRow = computed(() => isEditMode.value);
const shouldShowShareQrCode = computed(() => {
return isEditMode.value && Boolean(form.shareUrl);
Expand Down Expand Up @@ -782,6 +788,10 @@ const expiresUnitList = computed(() => [
label: t("sharePage.createShare.unit.year"),
value: "year",
},
{
label: t("sharePage.createShare.unit.lifetime"),
value: SHARE_LIFETIME_EXPIRATION_UNIT,
},
]);

const shareUrlQrCode = useQRCode(computed(() => form.shareUrl));
Expand Down Expand Up @@ -1246,8 +1256,8 @@ const normalizeExpiresValue = (expireValue: string) => {
return String(Number(Number.parseFloat(expireValue).toFixed(2)));
};

const genExpiresIn = (expireValue: string, expireUnit: ShareExpirationUnit) => {
const unitMap: Record<ShareExpirationUnit, { multiplier: number; suffix: string }> = {
const genExpiresIn = (expireValue: string, expireUnit: ShareTimedExpirationUnit) => {
const unitMap: Record<ShareTimedExpirationUnit, { multiplier: number; suffix: string }> = {
day: {
multiplier: 1,
suffix: "d",
Expand All @@ -1270,7 +1280,51 @@ const genExpiresIn = (expireValue: string, expireUnit: ShareExpirationUnit) => {
return `${value * unitConfig.multiplier}${unitConfig.suffix}`;
};

const getDurationExpirationOptions = (): ShareToken["options"] | null => {
const getDurationExpirationOptions = async (): Promise<ShareToken["options"] | null> => {
if (form.expiresUnit === SHARE_LIFETIME_EXPIRATION_UNIT) {
let verifiedEnv: { version?: string | null } | null = null;
try {
verifiedEnv = await ensureEnvLoaded({
forceRefresh: true,
strict: true,
});
} catch (error) {
console.error(error);
focusShareContentTab();
showNotify({
title: t("sharePage.editor.lifetimeBackendCheckFailed.title"),
content: t("sharePage.editor.lifetimeBackendCheckFailed.desc"),
type: "danger",
duration: 3600,
});
return null;
}

if (!supportsShareExpirationLifetime(verifiedEnv?.version)) {
focusShareContentTab();
showNotify({
title: t("sharePage.editor.lifetimeBackendRequired.title"),
content: t("sharePage.editor.lifetimeBackendRequired.desc", {
currentVersion: verifiedEnv?.version || t("specificWord.unknown"),
minVersion: SHARE_EXPIRATION_LIFETIME_BACKEND_VERSION,
}),
type: "danger",
duration: 3600,
});
return null;
}

if (!isDurationExpirationMode.value || form.expiresUnit !== SHARE_LIFETIME_EXPIRATION_UNIT) {
return null;
}

// 长期有效: 不传 expiresIn, 需显式声明 mode 让后端按长期有效保存
return {
mode: "duration",
expiresUnit: SHARE_LIFETIME_EXPIRATION_UNIT,
};
}

if (!form.expiresValue) {
focusShareContentTab();
Toast.warn(t("sharePage.createShare.expiresValue.empty"));
Expand Down Expand Up @@ -1419,7 +1473,7 @@ const getSubmitParams = async (): Promise<ShareToken | null> => {
} else if (isCountExpirationMode.value) {
options = getCountExpirationOptions();
} else {
options = getDurationExpirationOptions();
options = await getDurationExpirationOptions();
}
if (!options) {
return null;
Expand Down