You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-06-17 03:47:45 +02:00
refactor(web): shared link key auth (#3855)
This commit is contained in:
@ -14,10 +14,7 @@ const getExtensions = async () => {
|
||||
return _extensions;
|
||||
};
|
||||
|
||||
export const openFileUploadDialog = async (
|
||||
albumId: string | undefined = undefined,
|
||||
sharedKey: string | undefined = undefined,
|
||||
) => {
|
||||
export const openFileUploadDialog = async (albumId: string | undefined = undefined) => {
|
||||
const extensions = await getExtensions();
|
||||
|
||||
return new Promise<(string | undefined)[]>((resolve, reject) => {
|
||||
@ -34,7 +31,7 @@ export const openFileUploadDialog = async (
|
||||
}
|
||||
const files = Array.from(target.files);
|
||||
|
||||
resolve(fileUploadHandler(files, albumId, sharedKey));
|
||||
resolve(fileUploadHandler(files, albumId));
|
||||
};
|
||||
|
||||
fileSelector.click();
|
||||
@ -45,18 +42,14 @@ export const openFileUploadDialog = async (
|
||||
});
|
||||
};
|
||||
|
||||
export const fileUploadHandler = async (
|
||||
files: File[],
|
||||
albumId: string | undefined = undefined,
|
||||
sharedKey: string | undefined = undefined,
|
||||
) => {
|
||||
export const fileUploadHandler = async (files: File[], albumId: string | undefined = undefined) => {
|
||||
const extensions = await getExtensions();
|
||||
const iterable = {
|
||||
files: files.filter((file) => extensions.some((ext) => file.name.toLowerCase().endsWith(ext)))[Symbol.iterator](),
|
||||
|
||||
async *[Symbol.asyncIterator]() {
|
||||
for (const file of this.files) {
|
||||
yield fileUploader(file, albumId, sharedKey);
|
||||
yield fileUploader(file, albumId);
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -78,11 +71,7 @@ const fromAsync = async function <T>(iterable: AsyncIterable<T>) {
|
||||
};
|
||||
|
||||
// TODO: should probably use the @api SDK
|
||||
async function fileUploader(
|
||||
asset: File,
|
||||
albumId: string | undefined = undefined,
|
||||
sharedKey: string | undefined = undefined,
|
||||
): Promise<string | undefined> {
|
||||
async function fileUploader(asset: File, albumId: string | undefined = undefined): Promise<string | undefined> {
|
||||
const formData = new FormData();
|
||||
const fileCreatedAt = new Date(asset.lastModified).toISOString();
|
||||
const deviceAssetId = 'web' + '-' + asset.name + '-' + asset.lastModified;
|
||||
@ -103,9 +92,7 @@ async function fileUploader(
|
||||
});
|
||||
|
||||
const response = await axios.post('/api/asset/upload', formData, {
|
||||
params: {
|
||||
key: sharedKey,
|
||||
},
|
||||
params: { key: api.getKey() },
|
||||
onUploadProgress: (event) => {
|
||||
const percentComplete = Math.floor((event.loaded / event.total) * 100);
|
||||
uploadAssetsStore.updateProgress(deviceAssetId, percentComplete);
|
||||
@ -120,7 +107,7 @@ async function fileUploader(
|
||||
}
|
||||
|
||||
if (albumId && res.id) {
|
||||
await addAssetsToAlbum(albumId, [res.id], sharedKey);
|
||||
await addAssetsToAlbum(albumId, [res.id]);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
|
Reference in New Issue
Block a user