-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(golinks): update API docs and use @slack/oauth for all things bo…
…t tokens A lot of implementation details involve using Slack SDK packages, among other chores. To simplify bot token storage, we use a KV namespace for that in the moment. Relates to andreijiroh-dev/personal-launchpad#4 Signed-off-by: Andrei Jiroh Halili <[email protected]>
1 parent
b5d52a9
commit 01b8683
Showing
11 changed files
with
1,086 additions
and
405 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,116 @@ | ||
import { OpenAPIRoute, Num, Bool, Str, contentJson } from "chanfana"; | ||
import { z } from "zod"; | ||
import { GoLinks } from "types"; | ||
import { addGoLink, getGoLinks, updateGoLink } from "lib/db"; | ||
import { Context } from "hono"; | ||
|
||
export class WikiLinkCreate extends OpenAPIRoute { | ||
schema = { | ||
tags: ["wikilinks"], | ||
summary: "Create a golink-styled wikilink for `wiki.andreijiroh.xyz/go/*` and `andreijiroh.xyz/go/*`", | ||
request: { | ||
body: { | ||
content: { | ||
"application/json": { | ||
schema: z.object({ | ||
slug: Str({ required: true }), | ||
targetUrl: Str({ required: true, example: "https://github.com/integrations/slack" }), | ||
}), | ||
}, | ||
}, | ||
}, | ||
}, | ||
security: [ | ||
{ | ||
adminApiKey: [], | ||
}, | ||
], | ||
}; | ||
async handle(context) { | ||
const data = await this.getValidatedData<typeof this.schema>(); | ||
const linkToCreate = data.body; | ||
console.log(`[golinks-api] received body for link creation ${JSON.stringify(linkToCreate)}`); | ||
try { | ||
const result = await addGoLink(context.env.golink, linkToCreate.slug, linkToCreate.targetUrl, "wikilinks"); | ||
if (result) { | ||
return context.json({ | ||
ok: true, | ||
result, | ||
}); | ||
} else { | ||
return context.json( | ||
{ | ||
ok: false, | ||
error: "Something gone wrong while handling this request.", | ||
}, | ||
400, | ||
); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
return context.json( | ||
{ | ||
ok: false, | ||
error: "Internal server error", | ||
}, | ||
500, | ||
); | ||
} | ||
} | ||
} | ||
|
||
export class WikiLinkList extends OpenAPIRoute { | ||
schema = { | ||
tags: ["wikilinks"], | ||
summary: "List all golink-styled wikilinks", | ||
description: "Accessing this API route does not require authenication, although we also added it for higher API limits.", | ||
request: { | ||
query: z.object({ | ||
page: Num({ | ||
description: "Page number", | ||
default: 0, | ||
required: false, | ||
}), | ||
isActive: Bool({ | ||
description: "Filter by is_active status", | ||
required: false, | ||
}), | ||
}), | ||
}, | ||
security: [ | ||
{ | ||
adminApiKey: [], | ||
}, | ||
{ | ||
userApiKey: [], | ||
}, | ||
], | ||
responses: { | ||
"200": { | ||
description: "Returns a list of golinks", | ||
content: { | ||
"application/json": { | ||
schema: z.object({ | ||
series: z.object({ | ||
success: Bool(), | ||
result: GoLinks.array(), | ||
}), | ||
}), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
async handle(c) { | ||
const data = await this.getValidatedData<typeof this.schema>(); | ||
const { page, isActive } = data.query; | ||
|
||
const links = await getGoLinks(c.env.golinks, page !== undefined ? page : 0, isActive, "wikilinks"); | ||
|
||
return { | ||
success: true, | ||
result: links, | ||
}; | ||
} | ||
} |
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
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