mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Use cookies for client requests (#377)
* Use cookie for frontend request * Remove api helper to use SDK * Added error handling to status box * Remove additional places that check for session.user * Refactor sending password * prettier clean up * remove deadcode * Move all authentication requests to the client * refactor upload panel to only fetch assets after the upload panel disappear * Added keydown to remove focus on title change on album viewer
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
import { serverEndpoint } from '../constants';
|
||||
|
||||
type ISend = {
|
||||
method: string;
|
||||
path: string;
|
||||
data?: any;
|
||||
token: string;
|
||||
customHeaders?: Record<string, string>;
|
||||
};
|
||||
|
||||
type IOption = {
|
||||
method: string;
|
||||
headers: Record<string, string>;
|
||||
body: any;
|
||||
};
|
||||
|
||||
async function send({ method, path, data, token, customHeaders }: ISend) {
|
||||
const opts: IOption = { method, headers: {} } as IOption;
|
||||
|
||||
if (data) {
|
||||
opts.headers['Content-Type'] = 'application/json';
|
||||
opts.body = JSON.stringify(data);
|
||||
}
|
||||
|
||||
if (customHeaders) {
|
||||
console.log(customHeaders);
|
||||
// opts.headers[customHeader.$1]
|
||||
}
|
||||
|
||||
if (token) {
|
||||
opts.headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
return fetch(`${serverEndpoint}/${path}`, opts)
|
||||
.then((r) => r.text())
|
||||
.then((json) => {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch (err) {
|
||||
return json;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function getRequest(path: string, token: string, customHeaders?: Record<string, string>) {
|
||||
return send({ method: 'GET', path, token, customHeaders });
|
||||
}
|
||||
|
||||
export function delRequest(path: string, token: string, customHeaders?: Record<string, string>) {
|
||||
return send({ method: 'DELETE', path, token, customHeaders });
|
||||
}
|
||||
|
||||
export function postRequest(path: string, data: any, token: string, customHeaders?: Record<string, string>) {
|
||||
return send({ method: 'POST', path, data, token, customHeaders });
|
||||
}
|
||||
|
||||
export function putRequest(path: string, data: any, token: string, customHeaders?: Record<string, string>) {
|
||||
return send({ method: 'PUT', path, data, token, customHeaders });
|
||||
}
|
||||
@@ -11,8 +11,8 @@ type GithubRelease = {
|
||||
export const checkAppVersion = async (): Promise<CheckAppVersionReponse> => {
|
||||
const res = await fetch('https://api.github.com/repos/alextran1502/immich/releases/latest', {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
},
|
||||
Accept: 'application/vnd.github.v3+json'
|
||||
}
|
||||
});
|
||||
|
||||
if (res.status == 200) {
|
||||
@@ -23,7 +23,7 @@ export const checkAppVersion = async (): Promise<CheckAppVersionReponse> => {
|
||||
return {
|
||||
shouldShowAnnouncement: true,
|
||||
remoteVersion: latestRelease.tag_name,
|
||||
localVersion: 'empty',
|
||||
localVersion: 'empty'
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,20 +31,20 @@ export const checkAppVersion = async (): Promise<CheckAppVersionReponse> => {
|
||||
return {
|
||||
shouldShowAnnouncement: true,
|
||||
remoteVersion: latestRelease.tag_name,
|
||||
localVersion: appVersion,
|
||||
localVersion: appVersion
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
shouldShowAnnouncement: false,
|
||||
remoteVersion: latestRelease.tag_name,
|
||||
localVersion: appVersion,
|
||||
localVersion: appVersion
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
shouldShowAnnouncement: false,
|
||||
remoteVersion: '0',
|
||||
localVersion: '0',
|
||||
localVersion: '0'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,6 +10,6 @@ export function clickOutside(node: Node) {
|
||||
return {
|
||||
destroy() {
|
||||
document.removeEventListener('click', handleClick, true);
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { uploadAssetsStore } from '$lib/stores/upload';
|
||||
import type { UploadAsset } from '../models/upload-asset';
|
||||
import { api } from '@api';
|
||||
|
||||
export async function fileUploader(asset: File, accessToken: string) {
|
||||
export async function fileUploader(asset: File) {
|
||||
const assetType = asset.type.split('/')[0].toUpperCase();
|
||||
const temp = asset.name.split('.');
|
||||
const fileExtension = temp[temp.length - 1];
|
||||
@@ -56,7 +56,7 @@ export async function fileUploader(asset: File, accessToken: string) {
|
||||
|
||||
const { data, status } = await api.assetApi.checkDuplicateAsset({
|
||||
deviceAssetId: String(deviceAssetId),
|
||||
deviceId: 'WEB',
|
||||
deviceId: 'WEB'
|
||||
});
|
||||
|
||||
if (status === 200) {
|
||||
@@ -72,7 +72,7 @@ export async function fileUploader(asset: File, accessToken: string) {
|
||||
id: deviceAssetId,
|
||||
file: asset,
|
||||
progress: 0,
|
||||
fileExtension: fileExtension,
|
||||
fileExtension: fileExtension
|
||||
};
|
||||
|
||||
uploadAssetsStore.addNewUploadAsset(newUploadAsset);
|
||||
@@ -101,7 +101,6 @@ export async function fileUploader(asset: File, accessToken: string) {
|
||||
};
|
||||
|
||||
request.open('POST', `${serverEndpoint}/asset/upload`);
|
||||
request.setRequestHeader('Authorization', `Bearer ${accessToken}`);
|
||||
|
||||
request.send(formData);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user