final linting

This commit is contained in:
Sofía Aritz 2024-06-30 22:05:06 +02:00
parent 085215587c
commit 2935ab3f49
Signed by: sofia
GPG key ID: 90B5116E3542B28F
12 changed files with 72 additions and 52 deletions

View file

@ -6,7 +6,7 @@ The Asset API, takes care of storing user-generated assets.
1. Copy the `.env.example` file: `cp .env.example .env` 1. Copy the `.env.example` file: `cp .env.example .env`
2. Run `yarn` to install the dependencies. 2. Run `yarn` to install the dependencies.
* You may need to [enable Corepack](https://nodejs.org/api/corepack.html). - You may need to [enable Corepack](https://nodejs.org/api/corepack.html).
3. Run `yarn start` to start the server. 3. Run `yarn start` to start the server.
* You may need to create an empty folder at `$/asset-api/.keys`. - You may need to create an empty folder at `$/asset-api/.keys`.
4. You're ready to go! You will need to restart the server manually when you make changed (unless you use something like [Nodemon](https://www.npmjs.com/package/nodemon)). 4. You're ready to go! You will need to restart the server manually when you make changed (unless you use something like [Nodemon](https://www.npmjs.com/package/nodemon)).

View file

@ -38,5 +38,5 @@ export const LISTEN_PORT = Number(process.env["ASSET_API_LISTEN_PORT"]) || 3001;
export const ASSETS_FOLDER = process.env["ASSET_API_ASSETS_FOLDER"]; export const ASSETS_FOLDER = process.env["ASSET_API_ASSETS_FOLDER"];
export const IDENTITY_API_ENDPOINT = process.env["ASSET_API_IDENTITY_API_ENDPOINT"]; export const IDENTITY_API_ENDPOINT = process.env["ASSET_API_IDENTITY_API_ENDPOINT"];
export const M2M_ALGORITHM = process.env["ASSET_API_M2M_ALGORITHM"] || "RSA-SHA512"; export const M2M_ALGORITHM = process.env["ASSET_API_M2M_ALGORITHM"] || "RSA-SHA512";
export const PRIVATE_KEY_PATH = process.env["ASSET_API_PRIVATE_KEY_PATH"] export const PRIVATE_KEY_PATH = process.env["ASSET_API_PRIVATE_KEY_PATH"];
export const PUBLIC_KEY_PATH = process.env["ASSET_API_PUBLIC_KEY_PATH"] export const PUBLIC_KEY_PATH = process.env["ASSET_API_PUBLIC_KEY_PATH"];

View file

@ -24,7 +24,14 @@ import mime from "mime";
import { promisify } from "node:util"; import { promisify } from "node:util";
import { pipeline } from "node:stream"; import { pipeline } from "node:stream";
import cors from "@fastify/cors"; import cors from "@fastify/cors";
import { M2M_ALGORITHM, ASSETS_FOLDER, ASSET_API_LANDING_MESSAGE, IDENTITY_API_ENDPOINT, PRIVATE_KEY_PATH, PUBLIC_KEY_PATH } from "./consts.js"; import {
M2M_ALGORITHM,
ASSETS_FOLDER,
ASSET_API_LANDING_MESSAGE,
IDENTITY_API_ENDPOINT,
PRIVATE_KEY_PATH,
PUBLIC_KEY_PATH,
} from "./consts.js";
const { private: M2M_PRIVATE_KEY, public: M2M_PUBLIC_KEY } = loadM2MKeys(); const { private: M2M_PRIVATE_KEY, public: M2M_PUBLIC_KEY } = loadM2MKeys();
if (M2M_PRIVATE_KEY == null || M2M_PUBLIC_KEY == null) { if (M2M_PRIVATE_KEY == null || M2M_PUBLIC_KEY == null) {
@ -39,7 +46,7 @@ const app = new Fastify({
app.register(multipart); app.register(multipart);
app.register(cors, { app.register(cors, {
origin: true, origin: true,
}) });
app.get("/", async () => { app.get("/", async () => {
return signString(ASSET_API_LANDING_MESSAGE); return signString(ASSET_API_LANDING_MESSAGE);
@ -82,7 +89,7 @@ app.put("/asset", {
return { return {
asset_id: full_id, asset_id: full_id,
} };
}, },
schema: { schema: {
query: { query: {
@ -97,11 +104,11 @@ app.put("/asset", {
app.get("/asset", { app.get("/asset", {
async handler(request, reply) { async handler(request, reply) {
let { user, limits } = await userFromSessionKey(request.query.session_key); let { user } = await userFromSessionKey(request.query.session_key);
if ('statusCode' in user) { if ("statusCode" in user) {
reply.code(500); reply.code(500);
return "Something failed, please try again later" return "Something failed, please try again later";
} }
if (user.assets.includes(request.query.asset_id)) { if (user.assets.includes(request.query.asset_id)) {
@ -151,13 +158,13 @@ function loadM2MKeys() {
let privateDir = join(PRIVATE_KEY_PATH, ".."); let privateDir = join(PRIVATE_KEY_PATH, "..");
if (!existsSync(privateDir)) { if (!existsSync(privateDir)) {
console.warn("The private key folder does not exist. It will be created.") console.warn("The private key folder does not exist. It will be created.");
mkdirSync(privateDir, { recursive: true }); mkdirSync(privateDir, { recursive: true });
} }
let publicDir = join(PUBLIC_KEY_PATH, ".."); let publicDir = join(PUBLIC_KEY_PATH, "..");
if (!existsSync(publicDir)) { if (!existsSync(publicDir)) {
console.warn("The public key folder does not exist. It will be created.") console.warn("The public key folder does not exist. It will be created.");
mkdirSync(publicDir, { recursive: true }); mkdirSync(publicDir, { recursive: true });
} }

View file

@ -6,8 +6,8 @@ The Identity API, takes care of storing user data.
1. Copy the `.env.example` file: `cp .env.example .env` 1. Copy the `.env.example` file: `cp .env.example .env`
2. Run `yarn` to install the dependencies. 2. Run `yarn` to install the dependencies.
* You may need to [enable Corepack](https://nodejs.org/api/corepack.html). - You may need to [enable Corepack](https://nodejs.org/api/corepack.html).
3. Run `yarn start` to start the server. 3. Run `yarn start` to start the server.
* **Note:** The `asset-api` server **must** be running before this command is run. [More info](./docs/asset-implementation.md). - **Note:** The `asset-api` server **must** be running before this command is run. [More info](./docs/asset-implementation.md).
* You may need to create an empty folder at `$/identity-api/.database`. - You may need to create an empty folder at `$/identity-api/.database`.
4. You're ready to go! You will need to restart the server manually when you make changed (unless you use something like [Nodemon](https://www.npmjs.com/package/nodemon)). 4. You're ready to go! You will need to restart the server manually when you make changed (unless you use something like [Nodemon](https://www.npmjs.com/package/nodemon)).

View file

@ -37,7 +37,7 @@ export function fromDBList<T>(input: string): Array<T> {
export async function startDatabase() { export async function startDatabase() {
let dir = join(SQLITE_PATH, ".."); let dir = join(SQLITE_PATH, "..");
if (!existsSync(dir)) { if (!existsSync(dir)) {
console.warn("The database folder does not exist. It will be created.") console.warn("The database folder does not exist. It will be created.");
await mkdir(dir, { recursive: true }); await mkdir(dir, { recursive: true });
} }

View file

@ -23,7 +23,7 @@ let assetPubKey;
try { try {
assetPubKey = await fetchAssetPubkey(); assetPubKey = await fetchAssetPubkey();
} catch (e) { } catch (e) {
console.error("Couldn't retrieve the pubkey from the asset-api. Is the asset-api server running?") console.error("Couldn't retrieve the pubkey from the asset-api. Is the asset-api server running?");
process.exit(1); process.exit(1);
} }
@ -31,7 +31,7 @@ let assetAlgorithm;
try { try {
assetAlgorithm = await fetchAssetAlgorithm(); assetAlgorithm = await fetchAssetAlgorithm();
} catch (e) { } catch (e) {
console.error("Couldn't retrieve the algorithm from the asset-api. Is the asset-api server running?") console.error("Couldn't retrieve the algorithm from the asset-api. Is the asset-api server running?");
process.exit(1); process.exit(1);
} }

View file

@ -6,19 +6,19 @@ The web app that interacts with the Identiy API and the Asset API.
1. Copy the `.env.example` file: `cp .env.example .env` 1. Copy the `.env.example` file: `cp .env.example .env`
2. Run `yarn` to install the dependencies. 2. Run `yarn` to install the dependencies.
* You may need to [enable Corepack](https://nodejs.org/api/corepack.html). - You may need to [enable Corepack](https://nodejs.org/api/corepack.html).
3. Run `yarn dev` and open the specified URL. 3. Run `yarn dev` and open the specified URL.
4. You're ready to go! Any changes should be reflected in real time. 4. You're ready to go! Any changes should be reflected in real time.
## Structure ## Structure
* `./routes` - The pages and associated components. Part of the SvelteKit filesystem routing. - `./routes` - The pages and associated components. Part of the SvelteKit filesystem routing.
Most of the code is here. Most of the code is here.
* `./lib` - Various global elements. - `./lib` - Various global elements.
* `./lib/api.ts` - The stateless functions that interact with the Identity API and the Asset API. - `./lib/api.ts` - The stateless functions that interact with the Identity API and the Asset API.
* `./lib/stores.ts` - The global stores, used to store things like tokens and account info. - `./lib/stores.ts` - The global stores, used to store things like tokens and account info.
* `./lib/entry.ts` - The definitions for an entry. - `./lib/entry.ts` - The definitions for an entry.
- **Note:** This file may be moved to a common package in the near future to simplify the - **Note:** This file may be moved to a common package in the near future to simplify the
server development process. server development process.
* `./lib/assets` - Images used in the landing page. - `./lib/assets` - Images used in the landing page.
* `./lib/components` - Components used across various pages. - `./lib/components` - Components used across various pages.

View file

@ -126,21 +126,28 @@ export async function deleteEntry(credentials: Credentials, entry_id: string): P
await sendRequest('/entry', credentials, { method: 'DELETE' }, `?entry_id=${entry_id}`); await sendRequest('/entry', credentials, { method: 'DELETE' }, `?entry_id=${entry_id}`);
} }
export async function insertHeir(credentials: Credentials, heirs: InsertHeir): Promise<AccountHeir[]> { export async function insertHeir(
return await asJson(sendRequest('/auth/heirs', credentials, { credentials: Credentials,
method: 'PUT', heirs: InsertHeir
headers: { ): Promise<AccountHeir[]> {
'Content-Type': 'application/json' return await asJson(
}, sendRequest('/auth/heirs', credentials, {
body: JSON.stringify(heirs) method: 'PUT',
})); headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(heirs)
})
);
} }
export async function removeHeir(credentials: Credentials, heirID: string): Promise<AccountHeir[]> { export async function removeHeir(credentials: Credentials, heirID: string): Promise<AccountHeir[]> {
return await asJson(sendRequest('/auth/heirs', credentials, { return await asJson(
method: 'DELETE', sendRequest('/auth/heirs', credentials, {
body: heirID, method: 'DELETE',
})); body: heirID
})
);
} }
export async function listHeirs(credentials: Credentials): Promise<AccountHeir[]> { export async function listHeirs(credentials: Credentials): Promise<AccountHeir[]> {

View file

@ -5,7 +5,13 @@
<script lang="ts"> <script lang="ts">
import { createForm } from 'felte'; import { createForm } from 'felte';
import { account, credentials, refreshAccount } from '$lib/stores'; import { account, credentials, refreshAccount } from '$lib/stores';
import { type AccountHeir, type InsertHeir, insertHeir, listHeirs, removeHeir as removeDBHeir } from '$lib/api'; import {
type AccountHeir,
type InsertHeir,
insertHeir,
listHeirs,
removeHeir as removeDBHeir
} from '$lib/api';
credentials.subscribe( credentials.subscribe(
(v) => v == null && setTimeout(() => (window.location.pathname = '/auth/login'), 200) (v) => v == null && setTimeout(() => (window.location.pathname = '/auth/login'), 200)

View file

@ -125,7 +125,7 @@
<div class="mt-3.5 flex justify-center"> <div class="mt-3.5 flex justify-center">
<div class="flex w-[60%] flex-col"> <div class="flex w-[60%] flex-col">
<h1 class="pb-3.5 text-2xl"> <h1 class="pb-3.5 text-2xl">
Welcome back, <span class="font-bold">{$account?.name}</span>. Welcome back, <span class="font-bold">{$account?.name}.</span>
</h1> </h1>
{#if entries.length === 0} {#if entries.length === 0}
<a <a

View file

@ -172,9 +172,9 @@
{/if} {/if}
{/if} {/if}
{#if entry.base.kind === "environment" && typeof entry.base.location === "string"} {#if entry.base.kind === 'environment' && typeof entry.base.location === 'string'}
<div class="mb-1"> <div class="mb-1">
<FontAwesomeIcon class="pr-2" icon={faLocationDot}/> <FontAwesomeIcon class="pr-2" icon={faLocationDot} />
<span class="text-xl">{entry.base.location}</span> <span class="text-xl">{entry.base.location}</span>
</div> </div>
{/if} {/if}

View file

@ -99,7 +99,7 @@
values.spotify.length === 0 && values.spotify.length === 0 &&
values.yt.length === 0 && values.yt.length === 0 &&
values.otherProvider.length === 0 && values.otherProvider.length === 0 &&
(values.asset == null || typeof values.asset !== "object") (values.asset == null || typeof values.asset !== 'object')
) { ) {
errors['links'] = 'You must add at least one link or upload an audio asset'; errors['links'] = 'You must add at least one link or upload an audio asset';
} }