实现快传,完善快传和网盘的功能,实现文件的互传等一系列功能

This commit is contained in:
yoyuzh
2026-03-20 14:16:18 +08:00
parent 944ab6dbf8
commit 43358e29d7
109 changed files with 5237 additions and 2465 deletions

View File

@@ -0,0 +1,49 @@
import { apiRequest } from './api';
import { getTransferRouterMode, type TransferRouterMode } from './transfer-links';
import type { CreateFileShareLinkResponse, FileMetadata, FileShareDetailsResponse } from './types';
export const FILE_SHARE_ROUTE_PREFIX = '/share';
export function buildFileShareUrl(
origin: string,
token: string,
routerMode: TransferRouterMode = 'browser',
) {
const normalizedOrigin = origin.replace(/\/+$/, '');
const encodedToken = encodeURIComponent(token);
if (routerMode === 'hash') {
return `${normalizedOrigin}/#${FILE_SHARE_ROUTE_PREFIX}/${encodedToken}`;
}
return `${normalizedOrigin}${FILE_SHARE_ROUTE_PREFIX}/${encodedToken}`;
}
export function getPostLoginRedirectPath(nextPath: string | null, fallback = '/overview') {
if (!nextPath || !nextPath.startsWith('/') || nextPath.startsWith('//')) {
return fallback;
}
return nextPath;
}
export function createFileShareLink(fileId: number) {
return apiRequest<CreateFileShareLinkResponse>(`/files/${fileId}/share-links`, {
method: 'POST',
});
}
export function getFileShareDetails(token: string) {
return apiRequest<FileShareDetailsResponse>(`/files/share-links/${encodeURIComponent(token)}`);
}
export function importSharedFile(token: string, path: string) {
return apiRequest<FileMetadata>(`/files/share-links/${encodeURIComponent(token)}/import`, {
method: 'POST',
body: { path },
});
}
export function getCurrentFileShareUrl(token: string) {
return buildFileShareUrl(window.location.origin, token, getTransferRouterMode());
}