-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
73 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script lang="ts"> | ||
export let id: string | ||
async function revert() { | ||
// post request to /api/revert/<id>.json | ||
await fetch(`/api/revert/${id}.json`, { method: 'POST' }) | ||
} | ||
</script> | ||
|
||
<button on:click={revert} class="revert-button">Revert</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { RequestHandler } from '@sveltejs/kit' | ||
import type { JSONString } from '@sveltejs/kit/types/helper' | ||
import { fetchEntryHistoryItem } from '../../../lib/database/history' | ||
import { getRevertResult } from '../../../lib/revert' | ||
|
||
export interface APIHistoryItem { | ||
id: string | ||
entryId: string | ||
userId: string | ||
title: string | ||
content: string | ||
timestamp: Date | ||
} | ||
|
||
export interface APIHistoryResponse { | ||
count: number | ||
items: APIHistoryItem[] | ||
} | ||
|
||
// revert an entry history item | ||
export const post: RequestHandler = async req => { | ||
const historyItemId = req.params.id | ||
|
||
const historyItem = await fetchEntryHistoryItem(historyItemId) | ||
|
||
if (historyItem === null) | ||
return { | ||
status: 404, | ||
body: { | ||
error: 'Not found', | ||
}, | ||
} | ||
|
||
const newContent = await getRevertResult(historyItem) | ||
|
||
console.log(newContent) | ||
return { | ||
body: { | ||
content: newContent, | ||
} as unknown as JSONString, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters