mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-23 01:29:40 +02:00
fix: repository refresh will check if new a new commit is available
This commit is contained in:
@@ -72,8 +72,7 @@ router.post(
|
||||
if (repo.owner.id != user.id) {
|
||||
return res.status(401).json({ error: "not_authorized" });
|
||||
}
|
||||
await repo.updateStatus("preparing");
|
||||
await downloadQueue.add(repo, {jobId: repo.repoId});
|
||||
await repo.updateIfNeeded({ force: true });
|
||||
res.json({ status: repo.status });
|
||||
} catch (error) {
|
||||
handleError(error, res);
|
||||
@@ -95,7 +94,7 @@ router.delete(
|
||||
return res.status(401).json({ error: "not_authorized" });
|
||||
}
|
||||
await repo.updateStatus("removing");
|
||||
await removeQueue.add(repo, {jobId: repo.repoId});
|
||||
await removeQueue.add(repo, { jobId: repo.repoId });
|
||||
return res.json({ status: repo.status });
|
||||
} catch (error) {
|
||||
handleError(error, res);
|
||||
@@ -312,7 +311,7 @@ router.post(
|
||||
repo.model.conference = repoUpdate.conference;
|
||||
await repo.updateStatus("preparing");
|
||||
res.json({ status: repo.status });
|
||||
await downloadQueue.add(repo, {jobId: repo.repoId});
|
||||
await downloadQueue.add(repo, { jobId: repo.repoId });
|
||||
} catch (error) {
|
||||
return handleError(error, res);
|
||||
}
|
||||
@@ -376,7 +375,7 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
||||
}
|
||||
|
||||
res.send({ status: repo.status });
|
||||
downloadQueue.add(new Repository(repo), {jobId: repo.repoId});
|
||||
downloadQueue.add(new Repository(repo), { jobId: repo.repoId });
|
||||
} catch (error) {
|
||||
if (error.message?.indexOf(" duplicate key") > -1) {
|
||||
return handleError(
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as stream from "stream";
|
||||
import config from "../../config";
|
||||
|
||||
import { getRepo, handleError } from "./route-utils";
|
||||
import AnonymousError from "../AnonymousError";
|
||||
import { downloadQueue } from "../queue";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -59,6 +61,28 @@ router.get(
|
||||
) {
|
||||
redirectURL = repo.source.url;
|
||||
} else {
|
||||
if (
|
||||
repo.status == "expired" ||
|
||||
repo.status == "expiring" ||
|
||||
repo.status == "removing" ||
|
||||
repo.status == "removed"
|
||||
) {
|
||||
throw new AnonymousError("repository_expired", this);
|
||||
}
|
||||
|
||||
const fiveMinuteAgo = new Date();
|
||||
fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5);
|
||||
if (repo.status != "ready") {
|
||||
if (
|
||||
repo.model.statusDate < fiveMinuteAgo &&
|
||||
repo.status != "preparing"
|
||||
) {
|
||||
await repo.updateStatus("preparing");
|
||||
await downloadQueue.add(this, { jobId: repo.repoId });
|
||||
}
|
||||
throw new AnonymousError("repository_not_ready", this);
|
||||
}
|
||||
|
||||
await repo.updateIfNeeded();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user