Remove VITE_SERVER_ENDPOINT dependency (#428)

* Move backend api to its own instance

* Remove external fetch hook

* Added endpoint for album

* Added endpoint for admin page

* Make request directly to immich-server

* Refactor unsued code
This commit is contained in:
Alex
2022-08-06 18:14:54 -05:00
committed by GitHub
parent cf2b9eddfa
commit b68358766b
23 changed files with 152 additions and 66 deletions

View File

@@ -2,10 +2,12 @@
import type { Load } from '@sveltejs/kit';
import { api, UserResponseDto } from '@api';
export const load: Load = async () => {
export const load: Load = async ({ fetch }) => {
try {
const { data: allUsers } = await api.userApi.getAllUsers(false);
const { data: user } = await api.userApi.getMyUserInfo();
const [user, allUsers] = await Promise.all([
fetch('/data/user/get-my-user-info').then((r) => r.json()),
fetch('/data/user/get-all-users?isAll=false').then((r) => r.json())
]);
return {
status: 200,

View File

@@ -2,13 +2,15 @@
export const prerender = false;
import type { Load } from '@sveltejs/kit';
import { AlbumResponseDto, api } from '@api';
import { AlbumResponseDto } from '@api';
export const load: Load = async ({ params }) => {
export const load: Load = async ({ fetch, params }) => {
try {
const albumId = params['albumId'];
const { data: albumInfo } = await api.albumApi.getAlbumInfo(albumId);
const albumInfo = await fetch(`/data/album/get-album-info?albumId=${albumId}`).then((r) =>
r.json()
);
return {
status: 200,

View File

@@ -1,12 +1,10 @@
<script context="module" lang="ts">
export const prerender = false;
import { api } from '@api';
import type { Load } from '@sveltejs/kit';
export const load: Load = async ({ params }) => {
try {
await api.userApi.getMyUserInfo();
await fetch('/data/user/get-my-user-info');
} catch (e) {
return {
status: 302,

View File

@@ -9,10 +9,12 @@
import SideBar from '$lib/components/shared-components/side-bar/side-bar.svelte';
import { AlbumResponseDto, api } from '@api';
export const load: Load = async () => {
export const load: Load = async ({ fetch }) => {
try {
const { data: user } = await api.userApi.getMyUserInfo();
const { data: albums } = await api.albumApi.getAllAlbums();
const [user, albums] = await Promise.all([
fetch('/data/user/get-my-user-info').then((r) => r.json()),
fetch('/data/album/get-all-albums').then((r) => r.json())
]);
return {
status: 200,

View File

@@ -0,0 +1 @@
This directory contain SSR endpoints to user serverApi instance to make request directly to DNS

View File

@@ -0,0 +1,18 @@
import { AlbumResponseDto, serverApi } from '@api';
import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit';
export const GET = async ({
url
}: RequestEvent): Promise<RequestHandlerOutput<AlbumResponseDto>> => {
try {
const albumId = url.searchParams.get('albumId') || '';
const { data } = await serverApi.albumApi.getAlbumInfo(albumId);
return {
body: data
};
} catch {
return {
status: 500
};
}
};

View File

@@ -0,0 +1,18 @@
import { AlbumResponseDto, serverApi } from '@api';
import type { RequestEvent, RequestHandler, RequestHandlerOutput } from '@sveltejs/kit';
export const GET = async ({
url
}: RequestEvent): Promise<RequestHandlerOutput<AlbumResponseDto[]>> => {
try {
const isShared = url.searchParams.get('isShared') === 'true' || undefined;
const { data } = await serverApi.albumApi.getAllAlbums(isShared);
return {
body: data
};
} catch {
return {
status: 500
};
}
};

View File

@@ -0,0 +1,15 @@
import { AssetResponseDto, serverApi } from '@api';
import type { RequestHandlerOutput } from '@sveltejs/kit';
export const GET = async (): Promise<RequestHandlerOutput<AssetResponseDto[]>> => {
try {
const { data } = await serverApi.assetApi.getAllAssets();
return {
body: data
};
} catch {
return {
status: 500
};
}
};

View File

@@ -0,0 +1,17 @@
import { serverApi, UserResponseDto } from '@api';
import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit';
export const GET = async ({url} : RequestEvent): Promise<RequestHandlerOutput<UserResponseDto[]>> => {
try {
const isAll = url.searchParams.get('isAll') === 'true';
const { data } = await serverApi.userApi.getAllUsers(isAll);
return {
body: data
};
} catch {
return {
status: 500
};
}
};

View File

@@ -0,0 +1,15 @@
import { serverApi, UserResponseDto } from '@api';
import type { RequestHandlerOutput } from '@sveltejs/kit';
export const GET = async (): Promise<RequestHandlerOutput<UserResponseDto>> => {
try {
const { data } = await serverApi.userApi.getMyUserInfo();
return {
body: data
};
} catch {
return {
status: 500
};
}
};

View File

@@ -4,28 +4,31 @@
import { api } from '@api';
export const load: Load = async () => {
try {
const { data: user } = await api.userApi.getMyUserInfo();
if (browser) {
try {
const { data: user } = await api.userApi.getMyUserInfo();
return {
status: 302,
redirect: '/photos'
};
} catch (e) {}
const { data } = await api.userApi.getUserCount();
return {
status: 302,
redirect: '/photos'
status: 200,
props: {
isAdminUserExist: data.userCount == 0 ? false : true
}
};
} catch (e) {}
const { data } = await api.userApi.getUserCount();
return {
status: 200,
props: {
isAdminUserExist: data.userCount == 0 ? false : true
}
};
}
};
</script>
<script lang="ts">
import { goto } from '$app/navigation';
import { browser } from '$app/env';
export let isAdminUserExist: boolean;

View File

@@ -1,12 +1,12 @@
<script context="module" lang="ts">
export const prerender = false;
import { api } from '@api';
import type { Load } from '@sveltejs/kit';
export const load: Load = async () => {
export const load: Load = async ({ fetch }) => {
try {
await api.userApi.getMyUserInfo();
await fetch('/data/user/get-my-user-info');
return {
status: 302,
redirect: '/photos'

View File

@@ -2,20 +2,25 @@
export const prerender = false;
import type { Load } from '@sveltejs/kit';
import { getAssetsInfo } from '$lib/stores/assets';
import { setAssetInfo } from '$lib/stores/assets';
export const load: Load = async () => {
export const load: Load = async ({ fetch }) => {
try {
const { data } = await api.userApi.getMyUserInfo();
await getAssetsInfo();
const [userInfo, assets] = await Promise.all([
fetch('/data/user/get-my-user-info').then((r) => r.json()),
fetch('/data/asset/get-all-assets').then((r) => r.json())
]);
setAssetInfo(assets);
return {
status: 200,
props: {
user: data
user: userInfo
}
};
} catch (e) {
console.log('ERROR load photos index');
return {
status: 302,
redirect: '/auth/login'
@@ -33,7 +38,7 @@
import moment from 'moment';
import AssetViewer from '$lib/components/asset-viewer/asset-viewer.svelte';
import { openFileUploadDialog, UploadType } from '$lib/utils/file-uploader';
import { api, AssetResponseDto, UserResponseDto } from '@api';
import { AssetResponseDto, UserResponseDto } from '@api';
import SideBar from '$lib/components/shared-components/side-bar/side-bar.svelte';
export let user: UserResponseDto;

View File

@@ -4,10 +4,12 @@
import type { Load } from '@sveltejs/kit';
import { AlbumResponseDto, api, UserResponseDto } from '@api';
export const load: Load = async () => {
export const load: Load = async ({ fetch }) => {
try {
const { data: user } = await api.userApi.getMyUserInfo();
const { data: sharedAlbums } = await api.albumApi.getAllAlbums(true);
const [user, sharedAlbums] = await Promise.all([
fetch('/data/user/get-my-user-info').then((r) => r.json()),
fetch('/data/album/get-all-albums?isShared=true').then((r) => r.json())
]);
return {
status: 200,