Compare commits
3 Commits
0430186f7e
...
35d78dc617
Author | SHA1 | Date | |
---|---|---|---|
35d78dc617 | |||
43bdcfe9e1 | |||
fef36b8210 |
@ -1 +1 @@
|
||||
INFISCAL_TOKEN=set me
|
||||
INFISICAL_TOKEN=set me
|
41
src/database/models/player.ts
Normal file
41
src/database/models/player.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import mongoose, { Model } from "mongoose";
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const schema = new Schema({
|
||||
/**
|
||||
* The ID of the player
|
||||
*/
|
||||
_id: String,
|
||||
|
||||
scoresaber: {
|
||||
name: String,
|
||||
profilePicture: String,
|
||||
country: String,
|
||||
pp: Number,
|
||||
rank: Number,
|
||||
countryRank: Number,
|
||||
role: String,
|
||||
badges: [
|
||||
{
|
||||
image: String,
|
||||
description: String,
|
||||
},
|
||||
],
|
||||
histories: String,
|
||||
scoreStats: {
|
||||
totalScore: Number,
|
||||
totalRankedScore: Number,
|
||||
averageRankedAccuracy: Number,
|
||||
totalPlayCount: Number,
|
||||
rankedPlayCount: Number,
|
||||
replaysWatched: Number,
|
||||
},
|
||||
permissions: Number,
|
||||
banned: Boolean,
|
||||
inactive: Boolean,
|
||||
},
|
||||
});
|
||||
|
||||
export const PlayerSchema =
|
||||
(mongoose.models.Player as Model<typeof schema>) ||
|
||||
mongoose.model("Player", schema);
|
10
src/index.ts
10
src/index.ts
@ -8,15 +8,21 @@ import { createInfisicalClient } from "./util/secrets";
|
||||
// Load the environment variables
|
||||
dotenv.config();
|
||||
|
||||
const isValid = checkEnvironmentVariables("INFISCAL_TOKEN");
|
||||
const isValid = checkEnvironmentVariables("INFISICAL_TOKEN");
|
||||
if (!isValid) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
export const InfisicalClient = createInfisicalClient(
|
||||
process.env.INFISCAL_TOKEN!
|
||||
process.env.INFISICAL_TOKEN!
|
||||
);
|
||||
|
||||
console.log("---");
|
||||
console.log(
|
||||
"NOTE: If the infisical secret is invalid, it will say secrets are missing."
|
||||
);
|
||||
console.log("If this happens please check the env variable and/or the secret");
|
||||
console.log("---");
|
||||
// Load the secrets first so we ensure they are valid before starting the server
|
||||
initSecrets().then(async () => {
|
||||
await connectMongo();
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { GetOptions } from "infisical-node/src/types/InfisicalClient";
|
||||
import { InfisicalClient } from "..";
|
||||
|
||||
let MONGO_URI: string;
|
||||
@ -6,10 +7,18 @@ let MONGO_URI: string;
|
||||
* Initialize the secrets
|
||||
*/
|
||||
export async function initSecrets() {
|
||||
const mongoUri = (await InfisicalClient.getSecret("MONGO_URI")).secretValue;
|
||||
const options: GetOptions = {
|
||||
environment: process.env.NODE_ENV === "production" ? "main" : "dev",
|
||||
path: "/",
|
||||
type: "shared",
|
||||
};
|
||||
|
||||
const mongoUri = (await InfisicalClient.getSecret("MONGO_URI", options))
|
||||
.secretValue;
|
||||
|
||||
if (!mongoUri) {
|
||||
throw new Error("MONGO_URI not set in secrets");
|
||||
console.log("MONGO_URI not set in secrets");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
MONGO_URI = mongoUri;
|
||||
|
Reference in New Issue
Block a user