-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add log entry retrieval and deletion API endpoints
- Loading branch information
Showing
4 changed files
with
183 additions
and
0 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
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,41 @@ | ||
import { Handlers } from "$fresh/server.ts"; | ||
import { return_data, return_error } from "../../../server/utils.ts"; | ||
import { User, UserPermission } from "../../../db.ts"; | ||
import { parse_big_int } from "../../../server/parse_form.ts"; | ||
import { base_logger } from "../../../utils/logger.ts"; | ||
|
||
export const handler: Handlers = { | ||
async GET(_req, ctx) { | ||
const user = <User | undefined> ctx.state.user; | ||
if ( | ||
user && !user.is_admin && | ||
!(Number(user.permissions) & UserPermission.QueryLog) | ||
) { | ||
return return_error(403, "Permission denied."); | ||
} | ||
const id = await parse_big_int(ctx.params["id"], null); | ||
if (id === null) { | ||
return return_error(1, "id is required."); | ||
} | ||
const log = base_logger.get_log(id); | ||
if (!log) { | ||
return return_error(404, "log not found."); | ||
} | ||
return return_data(log); | ||
}, | ||
async DELETE(_req, ctx) { | ||
const user = <User | undefined> ctx.state.user; | ||
if ( | ||
user && !user.is_admin && | ||
!(Number(user.permissions) & UserPermission.QueryLog) | ||
) { | ||
return return_error(403, "Permission denied."); | ||
} | ||
const id = await parse_big_int(ctx.params["id"], null); | ||
if (id === null) { | ||
return return_error(1, "id is required."); | ||
} | ||
base_logger.delete_log(id); | ||
return return_data(true); | ||
}, | ||
}; |
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