2021-05-02 01:08:30 +00:00
|
|
|
import axios from 'axios'
|
2021-05-02 10:31:32 +00:00
|
|
|
import { dev } from '$app/env'
|
2021-05-02 01:08:30 +00:00
|
|
|
|
2021-05-02 10:31:32 +00:00
|
|
|
const base = axios.create({ baseURL: dev ? 'http://localhost:5000' : undefined })
|
2021-05-02 01:08:30 +00:00
|
|
|
|
|
|
|
export type Note = {
|
|
|
|
contents: string
|
|
|
|
password: boolean
|
|
|
|
views?: number
|
|
|
|
expiration?: number
|
|
|
|
}
|
|
|
|
export type NoteInfo = Pick<Note, 'password'>
|
|
|
|
export type NotePublic = Pick<Note, 'contents'>
|
|
|
|
|
|
|
|
export async function create(note: Note) {
|
|
|
|
const { data } = await base({
|
2021-05-02 12:02:40 +00:00
|
|
|
url: '/api/notes',
|
2021-05-02 01:08:30 +00:00
|
|
|
method: 'post',
|
|
|
|
data: note,
|
|
|
|
})
|
|
|
|
return data as { id: string }
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function get(id: string) {
|
|
|
|
const { data } = await base({
|
2021-05-02 12:02:40 +00:00
|
|
|
url: `/api/notes/${id}`,
|
2021-05-02 01:08:30 +00:00
|
|
|
method: 'delete',
|
|
|
|
})
|
|
|
|
return data as NotePublic
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function info(id: string) {
|
|
|
|
const { data } = await base({
|
2021-05-02 12:02:40 +00:00
|
|
|
url: `/api/notes/${id}`,
|
2021-05-02 01:08:30 +00:00
|
|
|
method: 'get',
|
|
|
|
})
|
|
|
|
return data as NoteInfo
|
|
|
|
}
|