mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2025-09-06 01:10:40 +00:00
one less dependency
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import { dev } from '$app/env'
|
||||
|
||||
const base = axios.create({ baseURL: dev ? 'http://localhost:5000' : undefined })
|
||||
|
||||
export type Note = {
|
||||
contents: string
|
||||
views?: number
|
||||
@@ -11,17 +8,34 @@ export type Note = {
|
||||
export type NoteInfo = {}
|
||||
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) {
|
||||
const { data } = await base({
|
||||
const data = await call({
|
||||
url: '/api/notes',
|
||||
method: 'post',
|
||||
data: note,
|
||||
body: note,
|
||||
})
|
||||
return data as { id: string }
|
||||
}
|
||||
|
||||
export async function get(id: string) {
|
||||
const { data } = await base({
|
||||
const data = await call({
|
||||
url: `/api/notes/${id}`,
|
||||
method: 'delete',
|
||||
})
|
||||
@@ -29,7 +43,7 @@ export async function get(id: string) {
|
||||
}
|
||||
|
||||
export async function info(id: string) {
|
||||
const { data } = await base({
|
||||
const data = await call({
|
||||
url: `/api/notes/${id}`,
|
||||
method: 'get',
|
||||
})
|
||||
|
Reference in New Issue
Block a user