one less dependency

This commit is contained in:
cupcakearmy 2021-05-07 14:09:26 +02:00
parent 70b53106ea
commit 2aa186450a
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
3 changed files with 21 additions and 49 deletions

View File

@ -6,7 +6,6 @@
"": { "": {
"dependencies": { "dependencies": {
"@fontsource/fira-mono": "^4.2.2", "@fontsource/fira-mono": "^4.2.2",
"axios": "^0.21.1",
"copy-to-clipboard": "^3.3.1" "copy-to-clipboard": "^3.3.1"
}, },
"devDependencies": { "devDependencies": {
@ -126,14 +125,6 @@
"url": "https://github.com/chalk/ansi-styles?sponsor=1" "url": "https://github.com/chalk/ansi-styles?sponsor=1"
} }
}, },
"node_modules/axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"dependencies": {
"follow-redirects": "^1.10.0"
}
},
"node_modules/chalk": { "node_modules/chalk": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz",
@ -233,25 +224,6 @@
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"dev": true "dev": true
}, },
"node_modules/follow-redirects": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.0.tgz",
"integrity": "sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/fsevents": { "node_modules/fsevents": {
"version": "2.3.2", "version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
@ -690,14 +662,6 @@
"color-convert": "^2.0.1" "color-convert": "^2.0.1"
} }
}, },
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"chalk": { "chalk": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz",
@ -770,11 +734,6 @@
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"dev": true "dev": true
}, },
"follow-redirects": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.0.tgz",
"integrity": "sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg=="
},
"fsevents": { "fsevents": {
"version": "2.3.2", "version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",

View File

@ -18,7 +18,6 @@
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@fontsource/fira-mono": "^4.2.2", "@fontsource/fira-mono": "^4.2.2",
"axios": "^0.21.1",
"copy-to-clipboard": "^3.3.1" "copy-to-clipboard": "^3.3.1"
} }
} }

View File

@ -1,8 +1,5 @@
import axios from 'axios'
import { dev } from '$app/env' import { dev } from '$app/env'
const base = axios.create({ baseURL: dev ? 'http://localhost:5000' : undefined })
export type Note = { export type Note = {
contents: string contents: string
views?: number views?: number
@ -11,17 +8,34 @@ export type Note = {
export type NoteInfo = {} export type NoteInfo = {}
export type NotePublic = Pick<Note, 'contents'> export type NotePublic = Pick<Note, 'contents'>
type CallOptions = {
url: string
method: string
body?: any
}
const base = dev ? 'http://localhost:5000' : undefined
async function call(options: CallOptions) {
return fetch(base + options.url, {
method: options.method,
body: options.body === undefined ? undefined : JSON.stringify(options.body),
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
}).then((r) => r.json())
}
export async function create(note: Note) { export async function create(note: Note) {
const { data } = await base({ const data = await call({
url: '/api/notes', url: '/api/notes',
method: 'post', method: 'post',
data: note, body: note,
}) })
return data as { id: string } return data as { id: string }
} }
export async function get(id: string) { export async function get(id: string) {
const { data } = await base({ const data = await call({
url: `/api/notes/${id}`, url: `/api/notes/${id}`,
method: 'delete', method: 'delete',
}) })
@ -29,7 +43,7 @@ export async function get(id: string) {
} }
export async function info(id: string) { export async function info(id: string) {
const { data } = await base({ const data = await call({
url: `/api/notes/${id}`, url: `/api/notes/${id}`,
method: 'get', method: 'get',
}) })