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`
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.
* 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)).
- 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)).

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 IDENTITY_API_ENDPOINT = process.env["ASSET_API_IDENTITY_API_ENDPOINT"];
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 PUBLIC_KEY_PATH = process.env["ASSET_API_PUBLIC_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"];

View file

@ -1,16 +1,16 @@
// Identity. Store your memories and mental belongings
// Copyright (C) 2024 Sofía Aritz
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
@ -24,7 +24,14 @@ import mime from "mime";
import { promisify } from "node:util";
import { pipeline } from "node:stream";
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();
if (M2M_PRIVATE_KEY == null || M2M_PUBLIC_KEY == null) {
@ -39,7 +46,7 @@ const app = new Fastify({
app.register(multipart);
app.register(cors, {
origin: true,
})
});
app.get("/", async () => {
return signString(ASSET_API_LANDING_MESSAGE);
@ -82,7 +89,7 @@ app.put("/asset", {
return {
asset_id: full_id,
}
};
},
schema: {
query: {
@ -97,11 +104,11 @@ app.put("/asset", {
app.get("/asset", {
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);
return "Something failed, please try again later"
return "Something failed, please try again later";
}
if (user.assets.includes(request.query.asset_id)) {
@ -151,13 +158,13 @@ function loadM2MKeys() {
let privateDir = join(PRIVATE_KEY_PATH, "..");
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 });
}
let publicDir = join(PUBLIC_KEY_PATH, "..");
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 });
}

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`
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.
* **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`.
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)).
- **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`.
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() {
let dir = join(SQLITE_PATH, "..");
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 });
}

View file

@ -23,7 +23,7 @@ let assetPubKey;
try {
assetPubKey = await fetchAssetPubkey();
} 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);
}
@ -31,7 +31,7 @@ let assetAlgorithm;
try {
assetAlgorithm = await fetchAssetAlgorithm();
} 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);
}

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`
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.
4. You're ready to go! Any changes should be reflected in real time.
## Structure
* `./routes` - The pages and associated components. Part of the SvelteKit filesystem routing.
Most of the code is here.
* `./lib` - Various global elements.
* `./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/entry.ts` - The definitions for an entry.
- **Note:** This file may be moved to a common package in the near future to simplify the
server development process.
* `./lib/assets` - Images used in the landing page.
* `./lib/components` - Components used across various pages.
- `./routes` - The pages and associated components. Part of the SvelteKit filesystem routing.
Most of the code is here.
- `./lib` - Various global elements.
- `./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/entry.ts` - The definitions for an entry.
- **Note:** This file may be moved to a common package in the near future to simplify the
server development process.
- `./lib/assets` - Images used in the landing page.
- `./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}`);
}
export async function insertHeir(credentials: Credentials, heirs: InsertHeir): Promise<AccountHeir[]> {
return await asJson(sendRequest('/auth/heirs', credentials, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(heirs)
}));
export async function insertHeir(
credentials: Credentials,
heirs: InsertHeir
): Promise<AccountHeir[]> {
return await asJson(
sendRequest('/auth/heirs', credentials, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(heirs)
})
);
}
export async function removeHeir(credentials: Credentials, heirID: string): Promise<AccountHeir[]> {
return await asJson(sendRequest('/auth/heirs', credentials, {
method: 'DELETE',
body: heirID,
}));
return await asJson(
sendRequest('/auth/heirs', credentials, {
method: 'DELETE',
body: heirID
})
);
}
export async function listHeirs(credentials: Credentials): Promise<AccountHeir[]> {

View file

@ -5,7 +5,13 @@
<script lang="ts">
import { createForm } from 'felte';
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(
(v) => v == null && setTimeout(() => (window.location.pathname = '/auth/login'), 200)
@ -64,7 +70,7 @@
</h1>
{#await heirs}
<span>Loading heirs...</span>
{:then heirs}
{:then heirs}
<div>
<div class="mb-2 flex justify-between">
<h2 class="pb-2.5 text-xl">Heirs</h2>

View file

@ -125,7 +125,7 @@
<div class="mt-3.5 flex justify-center">
<div class="flex w-[60%] flex-col">
<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>
{#if entries.length === 0}
<a

View file

@ -172,9 +172,9 @@
{/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">
<FontAwesomeIcon class="pr-2" icon={faLocationDot}/>
<FontAwesomeIcon class="pr-2" icon={faLocationDot} />
<span class="text-xl">{entry.base.location}</span>
</div>
{/if}

View file

@ -99,7 +99,7 @@
values.spotify.length === 0 &&
values.yt.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';
}