投票支持

This commit is contained in:
浪子
2026-05-14 19:29:34 +08:00
parent a2badc2d4f
commit e55a1a063d
5 changed files with 819 additions and 42 deletions
+46 -2
View File
@@ -18,14 +18,20 @@ import {
accountStatuses,
accountFollowers,
accountFollowing,
addListAccounts,
authorize,
authorizeFollowRequest,
authorizePage,
bookmarkStatus,
bookmarksList,
createApp,
createList,
createPushSubscription,
createStatus,
customEmojis,
deleteList,
deletePushSubscription,
deleteScheduledStatus,
deleteStatusEndpoint,
favouriteStatus,
favouritesList,
@@ -33,23 +39,32 @@ import {
followAccount,
followRequestsList,
getAccount,
getList,
getPoll,
getPushSubscription,
getRelationships,
getScheduledStatus,
getStatusEndpoint,
hashtagInfo,
hashtagTimeline,
homeTimeline,
instance,
instanceV2,
listAccounts,
listScheduledStatuses,
listTimeline,
listsList,
lookupAccount,
markersList,
notificationClear,
notificationDismiss,
notificationsList,
pinStatus,
publishDueScheduledStatuses,
publicTimeline,
pushSubscription,
reblogStatus,
rejectFollowRequest,
removeListAccounts,
revoke,
search,
serveMedia,
@@ -61,9 +76,13 @@ import {
unfollowAccount,
unpinStatus,
unreblogStatus,
updateList,
updatePushSubscription,
updateScheduledStatus,
updateCredentials,
updateMedia,
uploadMedia,
votePoll,
verifyAppCredentials,
verifyCredentials
} from "./mastodon";
@@ -72,12 +91,17 @@ export default {
async fetch(request: Request, env: Env): Promise<Response> {
try {
await ensureAdminUser(env);
await publishDueScheduledStatuses(env);
return await route(request, env);
} catch (error) {
if (error instanceof HttpError) return json({ error: error.message }, error.status);
console.error("unhandled", error);
return json({ error: "internal_server_error" }, 500);
}
},
async scheduled(_event: ScheduledEvent, env: Env): Promise<void> {
await ensureAdminUser(env);
await publishDueScheduledStatuses(env);
}
};
@@ -138,12 +162,29 @@ async function route(request: Request, env: Env): Promise<Response> {
if (method === "POST" && (m = path.match(/^\/api\/v1\/statuses\/([^/]+)\/unbookmark$/))) return unbookmarkStatus(request, env, decodeURIComponent(m[1]));
if (method === "POST" && (m = path.match(/^\/api\/v1\/statuses\/([^/]+)\/pin$/))) return pinStatus(request, env, decodeURIComponent(m[1]));
if (method === "POST" && (m = path.match(/^\/api\/v1\/statuses\/([^/]+)\/unpin$/))) return unpinStatus(request, env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/api\/v1\/polls\/([^/]+)$/))) return getPoll(request, env, decodeURIComponent(m[1]));
if (method === "POST" && (m = path.match(/^\/api\/v1\/polls\/([^/]+)\/votes$/))) return votePoll(request, env, decodeURIComponent(m[1]));
if (method === "GET" && path === "/api/v1/scheduled_statuses") return listScheduledStatuses(request, env);
if (method === "GET" && (m = path.match(/^\/api\/v1\/scheduled_statuses\/([^/]+)$/))) return getScheduledStatus(request, env, decodeURIComponent(m[1]));
if ((method === "PUT" || method === "PATCH") && (m = path.match(/^\/api\/v1\/scheduled_statuses\/([^/]+)$/))) return updateScheduledStatus(request, env, decodeURIComponent(m[1]));
if (method === "DELETE" && (m = path.match(/^\/api\/v1\/scheduled_statuses\/([^/]+)$/))) return deleteScheduledStatus(request, env, decodeURIComponent(m[1]));
if (method === "GET" && path === "/api/v1/timelines/public") return publicTimeline(request, env);
if (method === "GET" && path === "/api/v1/timelines/home") return homeTimeline(request, env);
if (method === "GET" && (m = path.match(/^\/api\/v1\/timelines\/list\/([^/]+)$/))) return listTimeline(request, env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/api\/v1\/timelines\/tag\/([^/]+)$/))) return hashtagTimeline(request, env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/api\/v1\/tags\/([^/]+)$/))) return hashtagInfo(env, decodeURIComponent(m[1]));
if (method === "GET" && path === "/api/v1/lists") return listsList(request, env);
if (method === "POST" && path === "/api/v1/lists") return createList(request, env);
if (method === "GET" && (m = path.match(/^\/api\/v1\/lists\/([^/]+)$/))) return getList(request, env, decodeURIComponent(m[1]));
if ((method === "PUT" || method === "PATCH") && (m = path.match(/^\/api\/v1\/lists\/([^/]+)$/))) return updateList(request, env, decodeURIComponent(m[1]));
if (method === "DELETE" && (m = path.match(/^\/api\/v1\/lists\/([^/]+)$/))) return deleteList(request, env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/api\/v1\/lists\/([^/]+)\/accounts$/))) return listAccounts(request, env, decodeURIComponent(m[1]));
if (method === "POST" && (m = path.match(/^\/api\/v1\/lists\/([^/]+)\/accounts$/))) return addListAccounts(request, env, decodeURIComponent(m[1]));
if (method === "DELETE" && (m = path.match(/^\/api\/v1\/lists\/([^/]+)\/accounts$/))) return removeListAccounts(request, env, decodeURIComponent(m[1]));
if (method === "GET" && path === "/api/v1/bookmarks") return bookmarksList(request, env);
if (method === "GET" && path === "/api/v1/favourites") return favouritesList(request, env);
@@ -159,7 +200,10 @@ async function route(request: Request, env: Env): Promise<Response> {
if (method === "GET" && path === "/api/v1/filters") return filtersV1(request, env);
if (method === "GET" && path === "/api/v1/trends/tags") return trendsTags(env);
if (method === "GET" && path === "/api/v1/markers") return markersList(request, env);
if (method === "POST" && path === "/api/v1/push/subscription") return pushSubscription();
if (method === "GET" && path === "/api/v1/push/subscription") return getPushSubscription(request, env);
if (method === "POST" && path === "/api/v1/push/subscription") return createPushSubscription(request, env);
if (method === "PUT" && path === "/api/v1/push/subscription") return updatePushSubscription(request, env);
if (method === "DELETE" && path === "/api/v1/push/subscription") return deletePushSubscription(request, env);
if (method === "GET" && (m = path.match(/^\/media\/(.+)$/))) return serveMedia(env, m[1]);