mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00:00
continue v2
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,8 @@
|
||||
.env
|
||||
repositories/
|
||||
repo/
|
||||
db_backups
|
||||
message.txt
|
||||
# Created by https://www.gitignore.io/api/node
|
||||
# Edit at https://www.gitignore.io/?templates=node
|
||||
|
||||
|
||||
@@ -66,11 +66,14 @@ GITHUB_TOKEN=<GITHUB_TOKEN>
|
||||
CLIENT_ID=<CLIENT_ID>
|
||||
CLIENT_SECRET=<CLIENT_SECRET>
|
||||
PORT=5000
|
||||
DB_USERNAME=
|
||||
DB_PASSWORD=
|
||||
AUTH_CALLBACK=http://localhost:5000/github/auth,
|
||||
```
|
||||
|
||||
`GITHUB_TOKEN` can be generate here: https://github.com/settings/tokens/new with `repo` scope.
|
||||
`CLIENT_ID` and `CLIENT_SECRET` are the tokens are generated when you create a new GitHub app https://github.com/settings/applications/new.
|
||||
The callback of the GitHub app needs to be defined as `https://<host>/github/auth`.
|
||||
The callback of the GitHub app needs to be defined as `https://<host>/github/auth` (the same as defined in AUTH_CALLBACK).
|
||||
|
||||
3. Run Anonymous Github
|
||||
```bash
|
||||
|
||||
@@ -27,8 +27,8 @@ services:
|
||||
ports:
|
||||
- "27017:27017"
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: root
|
||||
MONGO_INITDB_ROOT_PASSWORD: rootpassword
|
||||
MONGO_INITDB_ROOT_USERNAME: $DB_USERNAME
|
||||
MONGO_INITDB_ROOT_PASSWORD: $DB_PASSWORD
|
||||
volumes:
|
||||
- mongodb_data_container:/data/db
|
||||
command: --quiet
|
||||
@@ -42,5 +42,21 @@ services:
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
|
||||
mongodb-backup:
|
||||
image: tiredofit/db-backup
|
||||
links:
|
||||
- mongodb
|
||||
volumes:
|
||||
- ./db_backups:/backup
|
||||
environment:
|
||||
- DB_TYPE=mongo
|
||||
- DB_HOST=mongodb
|
||||
- DB_DUMP_FREQ=60
|
||||
- DB_CLEANUP_TIME=240
|
||||
- COMPRESSION=XZ
|
||||
- DB_USER=$DB_USERNAME
|
||||
- DB_PASS=$DB_PASSWORD
|
||||
|
||||
restart: always
|
||||
volumes:
|
||||
mongodb_data_container:
|
||||
|
||||
43
index.js
43
index.js
@@ -1,5 +1,6 @@
|
||||
const path = require("path");
|
||||
|
||||
const ofs = require("fs");
|
||||
const fs = require("fs").promises;
|
||||
const redis = require("redis");
|
||||
const RateLimit = require("express-rate-limit");
|
||||
const RedisStore = require("rate-limit-redis");
|
||||
@@ -22,16 +23,6 @@ const PORT = process.env.PORT || 5000;
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.use(compression());
|
||||
app.use(
|
||||
new RateLimit({
|
||||
store: new RedisStore({
|
||||
client: rediscli,
|
||||
}),
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: 200, // limit each IP to 100 requests per windowMs
|
||||
// delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
})
|
||||
);
|
||||
app.set("trust proxy", 1);
|
||||
|
||||
// handle session and connection
|
||||
@@ -39,15 +30,24 @@ app.use(connection.session);
|
||||
app.use(connection.passport.initialize());
|
||||
app.use(connection.passport.session());
|
||||
|
||||
app.use("/github", connection.router);
|
||||
const rateLimit = new RateLimit({
|
||||
store: new RedisStore({
|
||||
client: rediscli,
|
||||
}),
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: 200, // limit each IP to 100 requests per windowMs
|
||||
// delayMs: 0, // disable delaying - full speed until the max limit is reached
|
||||
});
|
||||
|
||||
app.use("/github", rateLimit, connection.router);
|
||||
|
||||
// app routes
|
||||
app.use("/api/user", require("./routes/user"));
|
||||
app.use("/api/repo", require("./routes/file"));
|
||||
app.use("/api/repo", require("./routes/repositoy"));
|
||||
app.use("/api/user", rateLimit, require("./routes/user"));
|
||||
app.use("/api/repo", rateLimit, require("./routes/file"));
|
||||
app.use("/api/repo", rateLimit, require("./routes/repositoy"));
|
||||
|
||||
// wesite view
|
||||
app.use("/w/", require("./routes/webview"));
|
||||
app.use("/w/", rateLimit, require("./routes/webview"));
|
||||
|
||||
app.use(express.static(__dirname + "/public"));
|
||||
|
||||
@@ -62,7 +62,7 @@ function exploreAppResponse(req, res) {
|
||||
res.sendFile(path.resolve(__dirname, "public", "explore.html"));
|
||||
}
|
||||
|
||||
app.get("/api/supportedTypes", async (req, res) => {
|
||||
app.get("/api/supportedTypes", async (_, res) => {
|
||||
res.json(
|
||||
require("textextensions")
|
||||
.default.concat(fileUtils.additionalExtensions)
|
||||
@@ -70,7 +70,14 @@ app.get("/api/supportedTypes", async (req, res) => {
|
||||
);
|
||||
});
|
||||
|
||||
app.get("/api/stat", async (req, res) => {
|
||||
app.get("/api/message", async (_, res) => {
|
||||
if (ofs.existsSync("./message.txt")) {
|
||||
return res.sendFile(path.resolve(__dirname, "message.txt"));
|
||||
}
|
||||
res.sendStatus(404);
|
||||
});
|
||||
|
||||
app.get("/api/stat", async (_, res) => {
|
||||
const nbRepositories = await db
|
||||
.get("anonymized_repositories")
|
||||
.estimatedDocumentCount();
|
||||
|
||||
@@ -41,10 +41,6 @@ router.get("/anonymized_repositories", async (req, res) => {
|
||||
repo.options.expirationDate != null &&
|
||||
repo.options.expirationDate < new Date()
|
||||
) {
|
||||
console.log(
|
||||
repo.options.expirationDate,
|
||||
repo.options.expirationDate < new Date()
|
||||
);
|
||||
await repoUtils.updateStatus({ repoId: repo.repoId }, "expired");
|
||||
repo.status = "expired";
|
||||
} else {
|
||||
|
||||
@@ -202,7 +202,6 @@ module.exports.getRepoCommit = async (options) => {
|
||||
force: options.force,
|
||||
});
|
||||
if (!branches[repoConfig.branch]) {
|
||||
console.log(branches, repoConfig.branch);
|
||||
throw "branch_not_found";
|
||||
}
|
||||
return branches[repoConfig.branch].commit.sha;
|
||||
|
||||
Reference in New Issue
Block a user