mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
api: add support for service name aliases
currently only used for bluesky
This commit is contained in:
parent
57050fb742
commit
740a75851e
3 changed files with 19 additions and 5 deletions
|
@ -1,12 +1,13 @@
|
|||
import { getVersion } from "@imput/version-info";
|
||||
import { services } from "./processing/service-config.js";
|
||||
import { friendlyServiceName } from "./processing/service-alias.js";
|
||||
|
||||
const version = await getVersion();
|
||||
|
||||
const disabledServices = process.env.DISABLED_SERVICES?.split(',') || [];
|
||||
const enabledServices = new Set(Object.keys(services).filter(e => {
|
||||
if (!disabledServices.includes(e)) {
|
||||
return e;
|
||||
return friendlyServiceName(e);
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import { createResponse } from "../processing/request.js";
|
|||
import { testers } from "./service-patterns.js";
|
||||
import matchAction from "./match-action.js";
|
||||
|
||||
import { friendlyServiceName } from "./service-alias.js";
|
||||
|
||||
import bilibili from "./services/bilibili.js";
|
||||
import reddit from "./services/reddit.js";
|
||||
import twitter from "./services/twitter.js";
|
||||
|
@ -59,7 +61,7 @@ export default async function(host, patternMatch, obj) {
|
|||
return createResponse("error", {
|
||||
code: "error.api.link.unsupported",
|
||||
context: {
|
||||
service: host
|
||||
service: friendlyServiceName(host),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -273,14 +275,14 @@ export default async function(host, patternMatch, obj) {
|
|||
case "link.unsupported":
|
||||
case "content.video.unavailable":
|
||||
context = {
|
||||
service: host,
|
||||
service: friendlyServiceName(host),
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return createResponse("error", {
|
||||
code: `error.api.${r.error}`,
|
||||
context
|
||||
context,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -301,7 +303,7 @@ export default async function(host, patternMatch, obj) {
|
|||
return createResponse("error", {
|
||||
code: "error.api.fetch.critical",
|
||||
context: {
|
||||
service: host
|
||||
service: friendlyServiceName(host),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
11
api/src/processing/service-alias.js
Normal file
11
api/src/processing/service-alias.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const friendlyNames = {
|
||||
bsky: "bluesky",
|
||||
}
|
||||
const friendlyKeys = Object.keys(friendlyNames);
|
||||
|
||||
export const friendlyServiceName = (service) => {
|
||||
if (service in friendlyKeys) {
|
||||
return friendlyNames[service];
|
||||
}
|
||||
return service;
|
||||
}
|
Loading…
Reference in a new issue