Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: connect page, apikey and v1 generation #134

Merged
merged 22 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3358c02
feat: remove unused variables
AyushSehrawat Oct 18, 2024
3d81f26
fix: update openapi client
AyushSehrawat Oct 18, 2024
388ea3c
fix: temporary update to rankings page
AyushSehrawat Oct 18, 2024
b7bd460
fix: frontend version showing unknown
AyushSehrawat Oct 18, 2024
76a2347
fix: lint
AyushSehrawat Oct 18, 2024
021563a
Merge branch 'main' into dev
AyushSehrawat Oct 18, 2024
fab80e7
feat: connect page, apikey and v1 generation
Oct 18, 2024
ef6db71
Merge branch 'dev' of https://github.com/rivenmedia/riven-frontend in…
Oct 18, 2024
3b3178b
chore: formatting, include format-all script
Oct 18, 2024
7102056
chore: eslint fixes
Oct 18, 2024
a021274
fix: invalid client api baseurl, onboarding hook moved to connect action
Oct 19, 2024
ee619e6
chore: generate new openapi client
Oct 19, 2024
a1d9133
chore: redirect to connect on invalid api key, validate on mount /con…
Oct 19, 2024
68def3b
fix: lint errors
davidemarcoli Oct 19, 2024
84eda1b
chore: move client config to svelte api, store serverconfig.json
Oct 21, 2024
6f4010c
Merge branch 'connect_apikey_apiv1' of https://github.com/rivenmedia/…
Oct 21, 2024
9a52664
Merge branch 'main' into connect_apikey_apiv1
Gaisberg Oct 21, 2024
28bced0
chore: linting fixes
Oct 21, 2024
3d394e8
Merge branch 'connect_apikey_apiv1' of https://github.com/rivenmedia/…
Oct 21, 2024
638291e
chore: set locals in hook
Oct 21, 2024
2eb66b8
chore: revert back client sided baseUrl configuration
Oct 21, 2024
a08994d
chore: linting fixes
Oct 21, 2024
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ vite.config.ts.timestamp-*
.idea
/.vs
/package-lock.json
.vscode
server-config.json
11 changes: 0 additions & 11 deletions .vscode/launch.json

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest",
"lint": "prettier --check . && eslint .",
"format": "prettier --write .",
"format": "prettier --write",
"format-all": "prettier --write .",
"generate-client": "openapi-ts generate"
},
"devDependencies": {
Expand Down
7 changes: 2 additions & 5 deletions src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
declare global {
namespace App {
// interface Error {}
interface Locals {
BACKEND_URL: string;
backendUrl: string;
apiKey: string;
}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hooks.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { client } from '$lib/client/services.gen';

client.setConfig({
baseUrl: '/api'
baseUrl: ''
});

client.interceptors.error.use((error: unknown) => {
Expand Down
70 changes: 42 additions & 28 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,55 @@
import type { Handle } from '@sveltejs/kit';
import { redirect, error } from '@sveltejs/kit';
import { redirect } from '@sveltejs/kit';
import { sequence } from '@sveltejs/kit/hooks';
import { env } from '$env/dynamic/private';
const BACKEND_URL = env.BACKEND_URL || 'http://127.0.0.1:8080';
import { client, DefaultService } from '$lib/client/services.gen';
import { client } from '$lib/client/services.gen';
import { getServerConfig } from '$lib/serverConfig';

const setLocals: Handle = async ({ event, resolve }) => {
event.locals.BACKEND_URL = BACKEND_URL;
const configureClientMiddleware: Handle = async ({ event, resolve }) => {
const config = await getServerConfig();

return resolve(event);
};
if (config) {
event.locals.backendUrl = config.backendUrl;
event.locals.apiKey = config.apiKey;
client.setConfig({
baseUrl: config.backendUrl,
headers: {
'x-api-key': config.apiKey
}
});
}

const onboarding: Handle = async ({ event, resolve }) => {
if (!(event.url.pathname.startsWith('/onboarding') || event.url.pathname.startsWith('/api')) && event.request.method === 'GET') {
const { data, error: apiError } = await DefaultService.services();
if (apiError || !data) {
return error(500, 'API Error');
}
const toCheck = ['symlink', 'symlinklibrary'];
const allServicesTrue: boolean = toCheck.every((service) => data[service] === true);
if (!allServicesTrue) {
redirect(302, '/onboarding');
if (
!event.url.pathname.startsWith('/connect') &&
!event.url.pathname.startsWith('/api/configure-client') &&
event.request.method === 'GET'
) {
if (!event.locals.backendUrl || !event.locals.apiKey) {
throw redirect(307, '/connect');
}
}

return resolve(event);
};

client.setConfig({
baseUrl: BACKEND_URL
});
const errorInterceptor: Handle = async ({ event, resolve }) => {
const response = await resolve(event);

client.interceptors.error.use((error: unknown) => {
if (error && typeof error == 'object' && 'detail' in error && typeof error.detail == 'string') {
return error.detail;
}
return undefined;
});
client.interceptors.error.use((error: unknown) => {
if (
error &&
typeof error === 'object' &&
'detail' in error &&
typeof error.detail === 'string'
) {
if (error.detail === 'Missing or invalid API key') {
throw redirect(307, '/connect');
}
return error.detail;
}
return undefined;
});

return response;
};

export const handle = sequence(setLocals, onboarding);
export const handle = sequence(configureClientMiddleware, errorInterceptor);
7 changes: 6 additions & 1 deletion src/lib/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ export const AppModelSchema = {
version: {
type: 'string',
title: 'Version',
default: '0.16.0'
default: '0.15.3'
},
api_key: {
type: 'string',
title: 'Api Key',
default: ''
},
debug: {
type: 'boolean',
Expand Down
Loading