Fix API inconsistencies

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-03-03 19:24:47 +01:00
parent 9e0433fc56
commit 2d3e4ede87
Signed by untrusted user: sam
GPG key ID: 4D8B07C18F31ACBD
2 changed files with 537 additions and 601 deletions

View file

@ -19,14 +19,14 @@ app.use(
function doCache(res, durationSecs) {
res.set({
"Cache-Control": "max-age="+durationSecs,
"Cache-Control": "max-age=" + durationSecs,
});
}
// this just redirects to the
app.options("/api/feed", cors());
app.get("/api/feed", cors(), logger, function(req, res) {
app.get("/api/feed", cors(), logger, function (req, res) {
// get feed url
const feedUrl = req.query.url;
if (!feedUrl) {
@ -38,11 +38,11 @@ app.get("/api/feed", cors(), logger, function(req, res) {
const userUrl = feedUrl.replace(/\.atom.*/i, "");
const redirectUrl = "/api/v1/feed?";
const qs = ["userurl="+encodeURIComponent(userUrl), "api=v1"];
const qs = [ "userurl=" + encodeURIComponent(userUrl), "api=v1" ];
(["size", "theme", "boosts", "replies"]).forEach((key)=>{
if (typeof req.query[key] != "undefined") {
qs.push(key+"="+encodeURIComponent(req.query[key]));
([ "size", "theme", "boosts", "replies" ]).forEach((key) => {
if (typeof req.query[ key ] != "undefined") {
qs.push(key + "=" + encodeURIComponent(req.query[ key ]));
}
});
@ -51,30 +51,28 @@ app.get("/api/feed", cors(), logger, function(req, res) {
app.options("/api/v1/feed", cors());
// http://localhost:8000/api/v1/feed?userurl=https%3A%2F%2Foctodon.social%2Fusers%2Ffenwick67
app.get("/api/v1/feed", cors(), logger, async function(req, res) {
app.get("/api/v1/feed", cors(), logger, async function (req, res) {
// get feed url
// userUrl
let type = req.query.instance_type;
let userUrl = "";
if (type === "") {
let userUrl = req.query.userurl;
if (userUrl === "" || userUrl === undefined) {
const user = req.query.user;
const instance = req.query.instance;
let instanceType = await detector(instance).catch(() =>
""
);
if (instanceType === "mastodon" || instanceType === "pleroma") {
if (type === "" || type === undefined) {
type = await detector(instance).catch(() =>
"",
);
}
if (type === "mastodon" || type === "pleroma")
userUrl = instance + "/users/" + user;
type = instanceType;
} else if (instanceType === "misskey") {
else if (type === "misskey")
userUrl = instance + "/@" + user;
type = instanceType;
} else {
res.status(500);
res.send(errorPage(500, "You need to specify a user URL"));
else {
res.status(400);
res.send(errorPage(400, "You need to specify a user URL"));
return;
}
} else {
userUrl = req.query.userurl;
}
const feedUrl = req.query.feedurl;
@ -127,6 +125,6 @@ app.get("/api/v1/feed", cors(), logger, async function(req, res) {
});
});
app.listen(process.env.PORT || 8000, function() {
console.log("Server started, listening on "+(process.env.PORT || 8000));
app.listen(process.env.PORT || 8000, function () {
console.log("Server started, listening on " + (process.env.PORT || 8000));
});

1094
yarn.lock

File diff suppressed because it is too large Load diff