mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00:00
Improve log and GH token validation
This commit is contained in:
@@ -28,6 +28,13 @@ export async function getToken(repository: Repository) {
|
||||
const span = trace.getTracer("ano-file").startSpan("GHUtils.getToken");
|
||||
span.setAttribute("repoId", repository.repoId);
|
||||
try {
|
||||
// only check the token if the repo has been visited more than one day ago
|
||||
if (
|
||||
repository.model.source.accessToken &&
|
||||
repository.model.lastView > new Date(Date.now() - 1000 * 60 * 60 * 24)
|
||||
) {
|
||||
return repository.model.source.accessToken;
|
||||
}
|
||||
if (repository.model.source.accessToken) {
|
||||
if (await checkToken(repository.model.source.accessToken)) {
|
||||
return repository.model.source.accessToken;
|
||||
@@ -48,6 +55,8 @@ export async function getToken(repository: Repository) {
|
||||
repository.owner.model.accessTokens?.github
|
||||
);
|
||||
if (check) {
|
||||
repository.model.source.accessToken =
|
||||
repository.owner.model.accessTokens?.github;
|
||||
return repository.owner.model.accessTokens?.github;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,23 @@ export default async function start() {
|
||||
keyGenerator,
|
||||
});
|
||||
|
||||
app.use(
|
||||
express.static(join("public"), {
|
||||
etag: true,
|
||||
lastModified: true,
|
||||
maxAge: 3600, // 1h
|
||||
})
|
||||
);
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
const start = Date.now();
|
||||
res.on("finish", function () {
|
||||
const time = Date.now() - start;
|
||||
console.log(`${req.method} ${join(req.baseUrl, req.url)} ${time}ms`);
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
||||
app.use("/github", rate, speedLimiter, connectionRouter);
|
||||
|
||||
// api routes
|
||||
@@ -201,14 +218,6 @@ export default async function start() {
|
||||
.get("/r/:repoId/?*", indexResponse)
|
||||
.get("/repository/:repoId/?*", indexResponse);
|
||||
|
||||
app.use(
|
||||
express.static(join("public"), {
|
||||
etag: true,
|
||||
lastModified: true,
|
||||
maxAge: 3600, // 1h
|
||||
})
|
||||
);
|
||||
|
||||
app.get("*", indexResponse);
|
||||
|
||||
// start schedules
|
||||
|
||||
@@ -58,8 +58,8 @@ router.get(
|
||||
// cache the file for 5min
|
||||
res.header("Cache-Control", "max-age=300");
|
||||
}
|
||||
await repo.countView();
|
||||
await f.send(res);
|
||||
await repo.countView();
|
||||
} catch (error) {
|
||||
return handleError(error, res, req);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
||||
commit: commit,
|
||||
getToken: () => token,
|
||||
});
|
||||
console.log(`[FILE] ${repoId}/${filePath}`);
|
||||
const content = await source.getFileContentCache(
|
||||
filePath,
|
||||
repoId,
|
||||
|
||||
Reference in New Issue
Block a user