mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
move store in local storage
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { IDocProps } from '../interfaces/IDocProps'
|
||||
import { ILatest } from '../interfaces/ILatest'
|
||||
import { IStoreItem } from '../interfaces/IStoreItem'
|
||||
|
||||
function checkStatus(res: Response) {
|
||||
if (res.status < 200 || res.status >= 400) {
|
||||
@@ -7,7 +7,7 @@ function checkStatus(res: Response) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function generatePdf(state: IDocProps): Promise<string> {
|
||||
export async function generatePdf(state: IDocProps): Promise<{ url: string; data: IStoreItem }> {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -18,18 +18,9 @@ export async function generatePdf(state: IDocProps): Promise<string> {
|
||||
|
||||
const response = await fetch('/api/document?template=brief', options)
|
||||
checkStatus(response)
|
||||
const { id } = await response.json()
|
||||
return `/api/document/${id}`
|
||||
}
|
||||
|
||||
export async function getLatest(): Promise<ILatest[]> {
|
||||
const response = await fetch('/api/document/latest')
|
||||
checkStatus(response)
|
||||
return response.json()
|
||||
}
|
||||
|
||||
export async function removeLatest(item: { id: string }) {
|
||||
const response = await fetch(`/api/document/${item.id}`, { method: 'DELETE' })
|
||||
checkStatus(response)
|
||||
return response
|
||||
const { id, data } = await response.json()
|
||||
return {
|
||||
url: `/api/document/${id}`,
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user