Port to node.js
This commit is contained in:
@@ -2,9 +2,11 @@ import { AttachmentId, PieceId, RepertoireId, Sha256 } from "common";
|
||||
import api, { NotFound, Role, Unauthorized } from "common/the_api";
|
||||
import { DateTime, Effect, HashSet, Number, Option, pipe } from "effect";
|
||||
import { sql } from "kysely";
|
||||
import { implement } from "./api";
|
||||
import * as Authentication from "./services/Authentication";
|
||||
import * as Database from "./services/Database";
|
||||
import * as crypto from "node:crypto";
|
||||
import * as uuid from "uuid";
|
||||
import { implement } from "./api.ts";
|
||||
import * as Authentication from "./services/Authentication.ts";
|
||||
import * as Database from "./services/Database.ts";
|
||||
|
||||
const READ_ACCESS = HashSet.make(Role.Admin, Role.Editor, Role.Viewer);
|
||||
const WRITE_ACCESS = HashSet.make(Role.Admin, Role.Editor);
|
||||
@@ -132,7 +134,7 @@ export const handle = implement(api, {
|
||||
const res = yield* db
|
||||
.insertInto("Piece")
|
||||
.values({
|
||||
pieceId: PieceId.make(Bun.randomUUIDv7()),
|
||||
pieceId: PieceId.make(uuid.v7()),
|
||||
name: piece.name,
|
||||
composer: Option.getOrNull(piece.composer),
|
||||
lyricist: Option.getOrNull(piece.lyricist),
|
||||
@@ -327,8 +329,8 @@ export const handle = implement(api, {
|
||||
.$call(Database.executeTakeFirst)
|
||||
.pipe(Effect.mapError(() => NotFound.make()));
|
||||
} else {
|
||||
sha256 = Sha256.make(new Uint8Array(Bun.SHA256.byteLength));
|
||||
Bun.SHA256.hash(attachment.data, sha256);
|
||||
const buffer = crypto.hash("sha256", attachment.data, { outputEncoding: "buffer" }) as Buffer<ArrayBuffer>;
|
||||
sha256 = Sha256.make(buffer);
|
||||
|
||||
yield* db
|
||||
.insertInto("File")
|
||||
@@ -340,7 +342,7 @@ export const handle = implement(api, {
|
||||
const res = yield* db
|
||||
.insertInto("Attachment")
|
||||
.values({
|
||||
attachmentId: AttachmentId.make(Bun.randomUUIDv7()),
|
||||
attachmentId: AttachmentId.make(uuid.v7()),
|
||||
pieceId: attachment.pieceId,
|
||||
filename: attachment.filename,
|
||||
mediaType: attachment.mediaType,
|
||||
@@ -430,7 +432,7 @@ export const handle = implement(api, {
|
||||
const { userId } = yield* requireOneOf(WRITE_ACCESS);
|
||||
const db = yield* Database.Database;
|
||||
|
||||
const repertoireId = RepertoireId.make(Bun.randomUUIDv7());
|
||||
const repertoireId = RepertoireId.make(uuid.v7());
|
||||
|
||||
const res = yield* db
|
||||
.insertInto("Repertoire")
|
||||
|
||||
Reference in New Issue
Block a user