reordering
This commit is contained in:
parent
07f4800d34
commit
cc9653d464
@ -1,10 +1,10 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
tab_width = 4
|
44
.gitignore → plugin/.gitignore
vendored
44
.gitignore → plugin/.gitignore
vendored
@ -1,22 +1,22 @@
|
||||
# vscode
|
||||
.vscode
|
||||
|
||||
# Intellij
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
|
||||
# Don't include the compiled main.js file in the repo.
|
||||
# They should be uploaded to GitHub releases instead.
|
||||
main.js
|
||||
|
||||
# Exclude sourcemaps
|
||||
*.map
|
||||
|
||||
# obsidian
|
||||
data.json
|
||||
|
||||
# Exclude macOS Finder (System Explorer) View States
|
||||
.DS_Store
|
||||
# vscode
|
||||
.vscode
|
||||
|
||||
# Intellij
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
|
||||
# Don't include the compiled main.js file in the repo.
|
||||
# They should be uploaded to GitHub releases instead.
|
||||
main.js
|
||||
|
||||
# Exclude sourcemaps
|
||||
*.map
|
||||
|
||||
# obsidian
|
||||
data.json
|
||||
|
||||
# Exclude macOS Finder (System Explorer) View States
|
||||
.DS_Store
|
@ -29,8 +29,7 @@ export class NoteSharingService {
|
||||
});
|
||||
|
||||
if (res.status == 200 && res.json != null) {
|
||||
const id = res.json.id;
|
||||
return `${this._url}/note/${id}`;
|
||||
return res.json.view_url;
|
||||
}
|
||||
throw Error("Did not get expected response from server on note POST.");
|
||||
}
|
9
server/.env
Normal file
9
server/.env
Normal file
@ -0,0 +1,9 @@
|
||||
# Environment variables declared in this file are automatically made available to Prisma.
|
||||
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
||||
|
||||
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
||||
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
||||
|
||||
PORT=8080
|
||||
FRONTEND_URL="http://localhost:3000"
|
||||
DATABASE_URL="file:./dev.db"
|
1
server/.gitignore
vendored
Normal file
1
server/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
16
server/build/server.js
Normal file
16
server/build/server.js
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const app = (0, express_1.default)();
|
||||
const port = 8080; // default port to listen
|
||||
// define a route handler for the default home page
|
||||
app.get("/", (req, res) => {
|
||||
res.send("Hello world!");
|
||||
});
|
||||
// start the Express server
|
||||
app.listen(port, () => {
|
||||
console.log(`server started at http://localhost:${port}!`);
|
||||
});
|
6970
server/package-lock.json
generated
Normal file
6970
server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
server/package.json
Normal file
30
server/package.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "obsidian-note-sharing-server",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "vitest",
|
||||
"build": "npx tsc",
|
||||
"dev": "npx nodemon ./server.ts"
|
||||
},
|
||||
"author": "Maxime Cannoodt (mcndt)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@prisma/client": "^3.15.2",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "^4.18.1",
|
||||
"sqlite3": "^5.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/node": "^18.0.0",
|
||||
"@types/sqlite3": "^3.1.8",
|
||||
"nodemon": "^2.0.16",
|
||||
"prisma": "^3.15.2",
|
||||
"supertest": "^6.2.3",
|
||||
"ts-node": "^10.8.1",
|
||||
"typescript": "^4.7.4",
|
||||
"vitest": "^0.15.1"
|
||||
}
|
||||
}
|
BIN
server/prisma/dev.db
Normal file
BIN
server/prisma/dev.db
Normal file
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "EncryptedNote" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"insert_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"ciphertext" BLOB NOT NULL,
|
||||
"hmac" BLOB NOT NULL
|
||||
);
|
@ -0,0 +1,13 @@
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_EncryptedNote" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"insert_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"ciphertext" TEXT NOT NULL,
|
||||
"hmac" TEXT NOT NULL
|
||||
);
|
||||
INSERT INTO "new_EncryptedNote" ("ciphertext", "hmac", "id", "insert_time") SELECT "ciphertext", "hmac", "id", "insert_time" FROM "EncryptedNote";
|
||||
DROP TABLE "EncryptedNote";
|
||||
ALTER TABLE "new_EncryptedNote" RENAME TO "EncryptedNote";
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
19
server/prisma/migrations/20220619175529_newid/migration.sql
Normal file
19
server/prisma/migrations/20220619175529_newid/migration.sql
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The primary key for the `EncryptedNote` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||
|
||||
*/
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_EncryptedNote" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"insert_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"ciphertext" TEXT NOT NULL,
|
||||
"hmac" TEXT NOT NULL
|
||||
);
|
||||
INSERT INTO "new_EncryptedNote" ("ciphertext", "hmac", "id", "insert_time") SELECT "ciphertext", "hmac", "id", "insert_time" FROM "EncryptedNote";
|
||||
DROP TABLE "EncryptedNote";
|
||||
ALTER TABLE "new_EncryptedNote" RENAME TO "EncryptedNote";
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
3
server/prisma/migrations/migration_lock.toml
Normal file
3
server/prisma/migrations/migration_lock.toml
Normal file
@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "sqlite"
|
18
server/prisma/schema.prisma
Normal file
18
server/prisma/schema.prisma
Normal file
@ -0,0 +1,18 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model EncryptedNote {
|
||||
id String @id @default(cuid())
|
||||
insert_time DateTime @default(now())
|
||||
ciphertext String
|
||||
hmac String
|
||||
}
|
43
server/server.ts
Normal file
43
server/server.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import "dotenv/config";
|
||||
import express, { Express, Request, Response } from "express";
|
||||
import { PrismaClient, EncryptedNote } from "@prisma/client";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const app: Express = express();
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
// start the Express server
|
||||
app.listen(process.env.PORT, () => {
|
||||
console.log(`server started at http://localhost:${process.env.PORT}`);
|
||||
});
|
||||
|
||||
// type EncryptedNote = {
|
||||
// id?: string;
|
||||
// ciphertext: string;
|
||||
// hmac: string;
|
||||
// };
|
||||
|
||||
// Post new encrypted note
|
||||
app.post("/note/", async (req: Request<{}, {}, EncryptedNote>, res) => {
|
||||
const note = req.body;
|
||||
const savedNote = await prisma.encryptedNote.create({ data: note });
|
||||
res.json({ view_url: `${process.env.FRONTEND_URL}/note/${savedNote.id}` });
|
||||
});
|
||||
|
||||
// Get encrypted note
|
||||
app.get("/note/:id", async (req, res) => {
|
||||
const note = await prisma.encryptedNote.findUnique({
|
||||
where: { id: req.params.id },
|
||||
});
|
||||
if (note != null) {
|
||||
res.send(note);
|
||||
}
|
||||
res.status(404).send();
|
||||
});
|
||||
|
||||
// Default response for any other request
|
||||
app.use((req, res, next) => {
|
||||
res.status(404).send();
|
||||
});
|
14
server/tsconfig.json
Normal file
14
server/tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"sourceMap": true,
|
||||
"lib": ["esnext"],
|
||||
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||
"module": "commonjs" /* Specify what module code is generated. */,
|
||||
"outDir": "./build" /* Specify an output folder for all emitted files. */,
|
||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
13
webapp/.eslintignore
Normal file
13
webapp/.eslintignore
Normal file
@ -0,0 +1,13 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
20
webapp/.eslintrc.cjs
Normal file
20
webapp/.eslintrc.cjs
Normal file
@ -0,0 +1,20 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
|
||||
plugins: ['svelte3', '@typescript-eslint'],
|
||||
ignorePatterns: ['*.cjs'],
|
||||
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
|
||||
settings: {
|
||||
'svelte3/typescript': () => require('typescript')
|
||||
},
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2020
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es2017: true,
|
||||
node: true
|
||||
}
|
||||
};
|
8
webapp/.gitignore
vendored
Normal file
8
webapp/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
1
webapp/.npmrc
Normal file
1
webapp/.npmrc
Normal file
@ -0,0 +1 @@
|
||||
engine-strict=true
|
13
webapp/.prettierignore
Normal file
13
webapp/.prettierignore
Normal file
@ -0,0 +1,13 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
6
webapp/.prettierrc
Normal file
6
webapp/.prettierrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100
|
||||
}
|
38
webapp/README.md
Normal file
38
webapp/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# create-svelte
|
||||
|
||||
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm init svelte
|
||||
|
||||
# create a new project in my-app
|
||||
npm init svelte my-app
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To create a production version of your app:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
6886
webapp/package-lock.json
generated
Normal file
6886
webapp/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
webapp/package.json
Normal file
40
webapp/package.json
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "obsidian-note-sharing-server",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "svelte-kit dev",
|
||||
"build": "svelte-kit build",
|
||||
"package": "svelte-kit package",
|
||||
"preview": "svelte-kit preview",
|
||||
"prepare": "svelte-kit sync",
|
||||
"check": "svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --check --plugin-search-dir=. . && eslint .",
|
||||
"format": "prettier --write --plugin-search-dir=. ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "next",
|
||||
"@sveltejs/kit": "^1.0.0-next.350",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
||||
"@typescript-eslint/parser": "^5.27.0",
|
||||
"autoprefixer": "^10.4.7",
|
||||
"eslint": "^8.16.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-svelte3": "^4.0.0",
|
||||
"postcss": "^8.4.14",
|
||||
"prettier": "^2.6.2",
|
||||
"prettier-plugin-svelte": "^2.7.0",
|
||||
"svelte": "^3.44.0",
|
||||
"svelte-check": "^2.7.1",
|
||||
"svelte-preprocess": "^4.10.7",
|
||||
"tailwindcss": "^3.1.3",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "^4.7.2"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"crypto-js": "^4.1.1",
|
||||
"svelte-markdown": "^0.2.2"
|
||||
}
|
||||
}
|
6
webapp/postcss.config.cjs
Normal file
6
webapp/postcss.config.cjs
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
5
webapp/src/app.css
Normal file
5
webapp/src/app.css
Normal file
@ -0,0 +1,5 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
|
10
webapp/src/app.d.ts
vendored
Normal file
10
webapp/src/app.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference types="@sveltejs/kit" />
|
||||
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare namespace App {
|
||||
// interface Locals {}
|
||||
// interface Platform {}
|
||||
// interface Session {}
|
||||
// interface Stuff {}
|
||||
}
|
27
webapp/src/app.html
Normal file
27
webapp/src/app.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
<script
|
||||
id="MathJax-script"
|
||||
async
|
||||
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"
|
||||
></script>
|
||||
<script>
|
||||
MathJax = {
|
||||
tex: {
|
||||
inlineMath: [
|
||||
['$', '$'],
|
||||
['\\(', '\\)']
|
||||
]
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div>%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
11
webapp/src/lib/components/Footer.svelte
Normal file
11
webapp/src/lib/components/Footer.svelte
Normal file
@ -0,0 +1,11 @@
|
||||
<footer class="p-8 text-center flex flex-wrap justify-center items-center gap-x-2 text-neutral-500">
|
||||
<span>
|
||||
Built with love by <a class="underline" href="https://mcndt.dev" alt="blog">mcndt</a>
|
||||
</span>
|
||||
<span>-</span>
|
||||
<a class="link" href="/about">About</a>
|
||||
<span>-</span>
|
||||
<a class="link" href="https://mcndt.dev/about/">Contact</a>
|
||||
<span>-</span>
|
||||
<a class="link" href="https://www.buymeacoffee.com/mcndt">☕ Buy me a coffee</a>
|
||||
</footer>
|
11
webapp/src/lib/components/MarkdownRenderer.svelte
Normal file
11
webapp/src/lib/components/MarkdownRenderer.svelte
Normal file
@ -0,0 +1,11 @@
|
||||
<script lang="ts">
|
||||
import SvelteMarkdown from 'svelte-markdown';
|
||||
import Heading from '$lib/renderers/Heading.svelte';
|
||||
import List from '$lib/renderers/List.svelte';
|
||||
|
||||
export let plaintext: string;
|
||||
</script>
|
||||
|
||||
<div id="md-box" class="space-y-6">
|
||||
<SvelteMarkdown renderers={{ heading: Heading, list: List }} source={plaintext} />
|
||||
</div>
|
17
webapp/src/lib/crypto/decrypt.ts
Normal file
17
webapp/src/lib/crypto/decrypt.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { AES, enc, HmacSHA256 } from 'crypto-js';
|
||||
|
||||
// TODO: should be same source code as used in the plugin!!
|
||||
export default function decrypt(cryptData: {
|
||||
ciphertext: string;
|
||||
hmac: string;
|
||||
key: string;
|
||||
}): string {
|
||||
const hmac_calculated = HmacSHA256(cryptData.ciphertext, cryptData.key).toString();
|
||||
const is_authentic = hmac_calculated == cryptData.hmac;
|
||||
|
||||
if (!is_authentic) {
|
||||
throw Error('Cannot decrypt ciphertext with this key.');
|
||||
}
|
||||
const md = AES.decrypt(cryptData.ciphertext, cryptData.key).toString(enc.Utf8);
|
||||
return md;
|
||||
}
|
6
webapp/src/lib/model/EncryptedNote.ts
Normal file
6
webapp/src/lib/model/EncryptedNote.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export type EncryptedNote = {
|
||||
id: string;
|
||||
insert_time: Date;
|
||||
ciphertext: string;
|
||||
hmac: string;
|
||||
};
|
29
webapp/src/lib/renderers/Heading.svelte
Normal file
29
webapp/src/lib/renderers/Heading.svelte
Normal file
@ -0,0 +1,29 @@
|
||||
<script lang="ts">
|
||||
// import { getContext } from 'svelte';
|
||||
// import { } from 'svelte-markdown';
|
||||
export let depth: number;
|
||||
export let raw: string;
|
||||
export let text: string;
|
||||
|
||||
// const { slug, getOptions } = getContext(key);
|
||||
// const options = getOptions();
|
||||
|
||||
$: id = undefined;
|
||||
// $: id = options.headerIds ? options.headerPrefix + slug(text) : undefined;
|
||||
</script>
|
||||
|
||||
{#if depth === 1}
|
||||
<h1 {id} class="text-3xl font-bold"><slot /></h1>
|
||||
{:else if depth === 2}
|
||||
<h2 {id} class="text-2xl font-bold"><slot /></h2>
|
||||
{:else if depth === 3}
|
||||
<h3 {id} class="text-xl font-bold"><slot /></h3>
|
||||
{:else if depth === 4}
|
||||
<h4 {id}><slot /></h4>
|
||||
{:else if depth === 5}
|
||||
<h5 {id}><slot /></h5>
|
||||
{:else if depth === 6}
|
||||
<h6 {id}><slot /></h6>
|
||||
{:else}
|
||||
{raw}
|
||||
{/if}
|
10
webapp/src/lib/renderers/List.svelte
Normal file
10
webapp/src/lib/renderers/List.svelte
Normal file
@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
export let ordered: boolean;
|
||||
export let start: number;
|
||||
</script>
|
||||
|
||||
{#if ordered}
|
||||
<ol class="list-decimal list-inside" {start}><slot /></ol>
|
||||
{:else}
|
||||
<ul class="list-disc list-inside"><slot /></ul>
|
||||
{/if}
|
10
webapp/src/routes/__layout.svelte
Normal file
10
webapp/src/routes/__layout.svelte
Normal file
@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
import Footer from '$lib/components/Footer.svelte';
|
||||
|
||||
import '../app.css';
|
||||
</script>
|
||||
|
||||
<div class="container mx-auto max-w-2xl mx-auto mt-6 px-4">
|
||||
<slot />
|
||||
<Footer />
|
||||
</div>
|
42
webapp/src/routes/index.svelte
Normal file
42
webapp/src/routes/index.svelte
Normal file
@ -0,0 +1,42 @@
|
||||
<script lang="ts" id="MathJax-script">
|
||||
import { onMount } from 'svelte';
|
||||
import { AES, HmacSHA256, enc } from 'crypto-js';
|
||||
import SvelteMarkdown from 'svelte-markdown';
|
||||
import Heading from '$lib/renderers/Heading.svelte';
|
||||
import List from '$lib/renderers/List.svelte';
|
||||
|
||||
import sample_crypto from './sample2.json';
|
||||
let plaintext: string = '';
|
||||
|
||||
onMount(() => {
|
||||
plaintext = decrypt(sample_crypto);
|
||||
});
|
||||
|
||||
function handleParsed(event: any) {
|
||||
//access tokens via event.detail.tokens
|
||||
console.log(event.detail.tokens);
|
||||
}
|
||||
|
||||
// TODO: should be same source code as used in the plugin!!
|
||||
function decrypt(cryptData: { ciphertext: string; hmac: string; key: string }): string {
|
||||
const hmac_calculated = HmacSHA256(cryptData.ciphertext, cryptData.key).toString();
|
||||
const is_authentic = hmac_calculated == cryptData.hmac;
|
||||
|
||||
if (!is_authentic) {
|
||||
throw Error('Cannot decrypt ciphertext with this key.');
|
||||
}
|
||||
const md = AES.decrypt(cryptData.ciphertext, cryptData.key).toString(enc.Utf8);
|
||||
return md;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="md-box" class="space-y-6">
|
||||
<SvelteMarkdown
|
||||
renderers={{ heading: Heading, list: List }}
|
||||
source={plaintext}
|
||||
on:parsed={handleParsed}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
</style>
|
46
webapp/src/routes/note/[id].svelte
Normal file
46
webapp/src/routes/note/[id].svelte
Normal file
@ -0,0 +1,46 @@
|
||||
<script context="module" , lang="ts">
|
||||
import type { Load } from '@sveltejs/kit';
|
||||
import type { EncryptedNote } from '$lib/model/EncryptedNote';
|
||||
|
||||
export const load: Load = async ({ params, fetch, session, stuff }) => {
|
||||
const url = `${import.meta.env.VITE_BACKEND_URL}/note/${params.id}`;
|
||||
const response = await fetch(url);
|
||||
const note: EncryptedNote = await response.json();
|
||||
|
||||
note.insert_time = new Date(note.insert_time as unknown as string);
|
||||
|
||||
return {
|
||||
status: response.status,
|
||||
props: { note }
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { browser } from '$app/env';
|
||||
import decrypt from '$lib/crypto/decrypt';
|
||||
import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte';
|
||||
|
||||
export let note: EncryptedNote;
|
||||
let plaintext: string;
|
||||
|
||||
onMount(() => {
|
||||
if (browser) {
|
||||
// Decrypt note
|
||||
const key = location.hash.slice(1);
|
||||
const start = performance.now();
|
||||
plaintext = decrypt({ ...note, key });
|
||||
console.log(performance.now() - start);
|
||||
}
|
||||
console.log(note.insert_time);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="mb-6">
|
||||
<p class="text-neutral-500">Note shared {note.insert_time.toLocaleString('en-GB')}</p>
|
||||
</div>
|
||||
|
||||
{#if plaintext}
|
||||
<MarkdownRenderer {plaintext} />
|
||||
{/if}
|
5
webapp/src/routes/sample.json
Normal file
5
webapp/src/routes/sample.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ciphertext": "U2FsdGVkX19INYDEiZRN16Vf0TPXnW9zGpmpwTPzFojXItJusegI3so9MqTPnYRh4FtI9xSIuzwRYJ3Kbs9yCjhKYq9GMTAzqV6sZWMVAR+VktqoaUN97hpoRKJ92yeUa9VU3VOkseiWmd15LMCp4++yqv8R5EvUb94Syu2sE9mWpPCl1s4VtnEDUu+67TZMbRJU95xSyJgucbY5fqlDMRtPXoUg/KHwn+Nm8iz9P2Gm/i0tE+H3xMcJvszeAEyEuBi76Raesew8r4MwRNQnaO6QN4EnAnHJib38a3oIOWD+LY1LKxdqakK1+b/e6oZOQkptXMFOxy9PbEOlNr+GjjOLnOIwYf/rF6TkH/sh9ocIgtfpDgkvIp+mrxhkBuzA4Ut2MY7TnlWp0pa9zbyTYu7ylrCazaz56/Pz63joCdtA/9q1wz/cjEjjzCXcr7SktPvkzQ82sXzxOgdVmWdj3gcGCVZAqeCusLrj48tVk8YjWoQhyZcg57yyaJSvvv4I8y2KM7dEypiEsocpVTlBnwVqJjQKqsVNWbtP/mjliYMZzHNnivnqhonroC0/7rqIRmlKDmlFFmYFIbOxXvoTzbR4/pSFNAckXmXAMlEuiRHSfBlWe7aSYFxLoIQFHwTZgbRgj+IQTH5edWRwbDIO70iMxoxjZVnFxtuLIwudTTDeStgKMl5lOFL+W4e31tJS4kFOboPrdMXXvcF9vBPHt0AQpDA10BoKLkhwSpQMgQsO1CZnYJ5Wv8pDFTulKqhSLisyD+TvkCYMoRCTxu7/mA3BVCSHt6EIScCyMtIQxB+P6sVvBld+a0+2k2qvNXIfv2xmcfrYYpBEGe+di9a68v6VQyCB47GP6JRLr1yN7b9pOkKwVAmKI8j4tk1gjxR201d41LfyTR3A0uDNqQZH89kQ037C/AyjPBvUandu2Kj0/NoPuDBWG6WlsRWL7cBXfBHr4q0mfjnSPjb0pBwZE10yxRtFDXEIKjcO6BKzI86lHypARtVEuVRrZst1+jwyB4JTN2gaTIUq2rRtLTwgV6plKN3A8/M8bu+LYS0J3YD3x4V0sCHDAyPjb+YePgPxunQrOD/bJkkdvDo5wrf0IOgxmessT17mP857tZCh/dlwkBkB+GNH2xVGwkltxowBqiX8c4bsuay+kDfoCXf2QmP5dYeyQJs+Ia0svsu03Bwo+qXhtovkTWBfBuOZp4BrO1F4UKh2gPuZp69aPbGeEICl0TnA0aayNug7j9vZuHr2a+0Q3L/4LINQp0SIWs2ZQjB7r/R2ZTAV5iJpt8ApwVwcByZKqhrlXWiPvKQZrUBUM1gklYG8XPL/hDjotuzi/UHPiG8vqbc++b8WapoIWa0bxO4QSV2ahhi5KcM8pmCc4dRf1TGTSG5EWuoItzl7EPL2fMeCwpgCCSJNcnX02wE+bme7UfrekrtXt4UYsKGwPPYdBHqFvRpnB8eFTx3y1FwzgO4HOdiraFgzGPOBZYKG075K0WRZy3qAp4LapA+mh26Vtc38KypAFGqRkKvImz4arohaIlgXpRx9fp9JBMqEXuhCWhamVvJ5WB5VsQShuRPOCPGvNdui8xjmvyq6",
|
||||
"hmac": "7fdb01d6706dafa2e807068f91192ed879d99699e43880054c3827a20d6d48ed",
|
||||
"key": "o4mlngqrvZB1KFy-HrXNKPal-j5tWuaWwGJSBHPmiM0"
|
||||
}
|
5
webapp/src/routes/sample2.json
Normal file
5
webapp/src/routes/sample2.json
Normal file
File diff suppressed because one or more lines are too long
BIN
webapp/static/favicon.png
Normal file
BIN
webapp/static/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
18
webapp/svelte.config.js
Normal file
18
webapp/svelte.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import adapter from '@sveltejs/adapter-auto';
|
||||
import preprocess from 'svelte-preprocess';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://github.com/sveltejs/svelte-preprocess
|
||||
// for more information about preprocessors
|
||||
preprocess: [
|
||||
preprocess({
|
||||
postcss: true
|
||||
})
|
||||
],
|
||||
kit: {
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
8
webapp/tailwind.config.cjs
Normal file
8
webapp/tailwind.config.cjs
Normal file
@ -0,0 +1,8 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ['./src/**/*.{html,js,svelte,ts}'],
|
||||
theme: {
|
||||
extend: {}
|
||||
},
|
||||
plugins: []
|
||||
};
|
17
webapp/tsconfig.json
Normal file
17
webapp/tsconfig.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true
|
||||
},
|
||||
"paths": {
|
||||
"$lib": ["src/lib"],
|
||||
"$lib/*": ["src/lib/*"]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user