mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 10:52:53 +00:00
migrate JavaScript to TypeScript
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import * as mongoose from "mongoose";
|
||||
const { model } = mongoose;
|
||||
|
||||
import {
|
||||
IAnonymizedRepositoryDocument,
|
||||
IAnonymizedRepositoryModel,
|
||||
} from "./anonymizedRepositories.types";
|
||||
import AnonymizedRepositorySchema from "./anonymizedRepositories.schema";
|
||||
|
||||
const AnonymizedRepositoryModel = model<IAnonymizedRepositoryDocument>(
|
||||
"AnonymizedRepository",
|
||||
AnonymizedRepositorySchema
|
||||
) as IAnonymizedRepositoryModel;
|
||||
|
||||
export default AnonymizedRepositoryModel;
|
||||
@@ -0,0 +1,54 @@
|
||||
import * as mongoose from "mongoose";
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const AnonymizedRepositorySchema = new Schema({
|
||||
repoId: {
|
||||
type: String,
|
||||
index: { unique: true },
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
default: "preparing",
|
||||
},
|
||||
errorMessage: String,
|
||||
anonymizeDate: Date,
|
||||
lastView: Date,
|
||||
pageView: Number,
|
||||
accessToken: String,
|
||||
owner: String,
|
||||
conference: String,
|
||||
source: {
|
||||
type: { type: String },
|
||||
branch: String,
|
||||
commit: String,
|
||||
repositoryId: String,
|
||||
repositoryName: String,
|
||||
accessToken: String,
|
||||
},
|
||||
originalFiles: mongoose.Schema.Types.Mixed,
|
||||
options: {
|
||||
terms: [String],
|
||||
expirationMode: { type: String },
|
||||
expirationDate: Date,
|
||||
update: Boolean,
|
||||
image: Boolean,
|
||||
pdf: Boolean,
|
||||
notebook: Boolean,
|
||||
link: Boolean,
|
||||
page: Boolean,
|
||||
pageSource: {
|
||||
branch: String,
|
||||
path: String,
|
||||
},
|
||||
},
|
||||
dateOfEntry: {
|
||||
type: Date,
|
||||
default: new Date(),
|
||||
},
|
||||
size: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
export default AnonymizedRepositorySchema;
|
||||
@@ -0,0 +1,46 @@
|
||||
import * as mongoose from "mongoose";
|
||||
import { RepositoryStatus, Tree } from "../../types";
|
||||
|
||||
export interface IAnonymizedRepository {
|
||||
repoId: string;
|
||||
status?: RepositoryStatus;
|
||||
errorMessage?: string;
|
||||
anonymizeDate: Date;
|
||||
source: {
|
||||
type: "GitHubDownload" | "GitHubStream" | "Zip";
|
||||
branch?: string;
|
||||
commit?: string;
|
||||
repositoryId?: string;
|
||||
repositoryName?: string;
|
||||
accessToken?: string;
|
||||
};
|
||||
owner: string;
|
||||
originalFiles: Tree;
|
||||
conference: string;
|
||||
options: {
|
||||
terms: string[];
|
||||
expirationMode: "never" | "redirect" | "remove";
|
||||
expirationDate?: Date;
|
||||
update: boolean;
|
||||
image: boolean;
|
||||
pdf: boolean;
|
||||
notebook: boolean;
|
||||
link: boolean;
|
||||
page: boolean;
|
||||
pageSource?: {
|
||||
branch: string;
|
||||
path: string;
|
||||
};
|
||||
};
|
||||
pageView: number;
|
||||
lastView: Date;
|
||||
size: number;
|
||||
}
|
||||
|
||||
export interface IAnonymizedRepositoryDocument
|
||||
extends IAnonymizedRepository,
|
||||
mongoose.Document {
|
||||
setLastUpdated: (this: IAnonymizedRepositoryDocument) => Promise<void>;
|
||||
}
|
||||
export interface IAnonymizedRepositoryModel
|
||||
extends mongoose.Model<IAnonymizedRepositoryDocument> {}
|
||||
28
src/database/database.ts
Normal file
28
src/database/database.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import * as mongoose from "mongoose";
|
||||
import Repository from "../Repository";
|
||||
import config from "../../config";
|
||||
import AnonymizedRepositoryModel from "./anonymizedRepositories/anonymizedRepositories.model";
|
||||
|
||||
const MONGO_URL = `mongodb://${config.DB_USERNAME}:${config.DB_PASSWORD}@${config.DB_HOSTNAME}:27017/`;
|
||||
|
||||
export const database = mongoose.connection;
|
||||
|
||||
export async function connect() {
|
||||
mongoose.set("useNewUrlParser", true);
|
||||
mongoose.set("useFindAndModify", true);
|
||||
mongoose.set("useUnifiedTopology", true);
|
||||
|
||||
await mongoose.connect(MONGO_URL + "test", {
|
||||
authSource: "admin",
|
||||
useCreateIndex: true,
|
||||
useFindAndModify: true,
|
||||
});
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
export async function getRepository(repoId: string) {
|
||||
const data = await AnonymizedRepositoryModel.findOne({ repoId });
|
||||
if (!data) throw new Error("repo_not_found");
|
||||
return new Repository(data);
|
||||
}
|
||||
12
src/database/repositories/repositories.model.ts
Normal file
12
src/database/repositories/repositories.model.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as mongoose from "mongoose";
|
||||
const { model } = mongoose;
|
||||
|
||||
import { IRepositoryDocument, IRepositoryModel } from "./repositories.types";
|
||||
import RepositorySchema from "./repositories.schema";
|
||||
|
||||
const RepositoryModel = model<IRepositoryDocument>(
|
||||
"Repository",
|
||||
RepositorySchema
|
||||
) as IRepositoryModel;
|
||||
|
||||
export default RepositoryModel;
|
||||
42
src/database/repositories/repositories.schema.ts
Normal file
42
src/database/repositories/repositories.schema.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import * as mongoose from "mongoose";
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const RepositorySchema = new Schema({
|
||||
externalId: {
|
||||
type: String,
|
||||
index: { unique: true },
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
index: true,
|
||||
},
|
||||
url: String,
|
||||
source: {
|
||||
type: String,
|
||||
default: "github",
|
||||
},
|
||||
hasPage: { type: Boolean, default: false },
|
||||
pageSource: {
|
||||
branch: { type: String },
|
||||
path: String,
|
||||
},
|
||||
branches: [
|
||||
{
|
||||
name: { type: String },
|
||||
commit: String,
|
||||
readme: String,
|
||||
},
|
||||
],
|
||||
defaultBranch: String,
|
||||
size: Number,
|
||||
status: {
|
||||
type: String,
|
||||
default: "ready",
|
||||
},
|
||||
dateOfEntry: {
|
||||
type: Date,
|
||||
default: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
export default RepositorySchema;
|
||||
25
src/database/repositories/repositories.types.ts
Normal file
25
src/database/repositories/repositories.types.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as mongoose from "mongoose";
|
||||
|
||||
export interface IRepository {
|
||||
externalId: string;
|
||||
name: string;
|
||||
url?: string;
|
||||
source: "github";
|
||||
size?: number;
|
||||
defaultBranch?: string;
|
||||
hasPage: boolean;
|
||||
pageSource?: {
|
||||
branch: string;
|
||||
path: string;
|
||||
};
|
||||
branches?: {
|
||||
name: string;
|
||||
commit: string;
|
||||
readme?: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface IRepositoryDocument extends IRepository, mongoose.Document {
|
||||
setLastUpdated: (this: IRepositoryDocument) => Promise<void>;
|
||||
}
|
||||
export interface IRepositoryModel extends mongoose.Model<IRepositoryDocument> {}
|
||||
10
src/database/users/users.model.ts
Normal file
10
src/database/users/users.model.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as mongoose from "mongoose";
|
||||
const { model } = mongoose;
|
||||
|
||||
import { IUserDocument, IUserModel } from "./users.types";
|
||||
import UserSchema from "./users.schema";
|
||||
|
||||
const UserModel = model<IUserDocument>("user", UserSchema) as IUserModel;
|
||||
|
||||
export default UserModel
|
||||
|
||||
36
src/database/users/users.schema.ts
Normal file
36
src/database/users/users.schema.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import * as mongoose from "mongoose";
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const UserSchema = new Schema({
|
||||
accessToken: String,
|
||||
username: {
|
||||
type: String,
|
||||
index: { unique: true },
|
||||
},
|
||||
email: String,
|
||||
photo: String,
|
||||
repositories: [String],
|
||||
default: {
|
||||
terms: [String],
|
||||
options: {
|
||||
expirationMode: { type: String },
|
||||
update: Boolean,
|
||||
image: Boolean,
|
||||
pdf: Boolean,
|
||||
notebook: Boolean,
|
||||
loc: Boolean,
|
||||
link: Boolean,
|
||||
page: { type: String },
|
||||
},
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
default: "active",
|
||||
},
|
||||
dateOfEntry: {
|
||||
type: Date,
|
||||
default: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
export default UserSchema;
|
||||
32
src/database/users/users.types.ts
Normal file
32
src/database/users/users.types.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as mongoose from "mongoose";
|
||||
|
||||
export interface IUser {
|
||||
accessToken: string;
|
||||
|
||||
username: string;
|
||||
email: string;
|
||||
photo?: string;
|
||||
|
||||
repositories?: number[];
|
||||
default?: {
|
||||
terms: string[];
|
||||
options: {
|
||||
expirationMode: "never" | "redirect" | "";
|
||||
update: boolean;
|
||||
image: boolean;
|
||||
pdf: boolean;
|
||||
notebook: boolean;
|
||||
loc: boolean;
|
||||
link: boolean;
|
||||
page: string | null;
|
||||
};
|
||||
};
|
||||
status?: "active" | "removed";
|
||||
dateOfEntry?: Date;
|
||||
lastUpdated?: Date;
|
||||
}
|
||||
|
||||
export interface IUserDocument extends IUser, mongoose.Document {
|
||||
setLastUpdated: (this: IUserDocument) => Promise<void>;
|
||||
}
|
||||
export interface IUserModel extends mongoose.Model<IUserDocument> {}
|
||||
Reference in New Issue
Block a user