Skip to content

Commit

Permalink
fix: packs, and some small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Feb 4, 2025
1 parent 0e62b5c commit 063b80b
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 31 deletions.
9 changes: 5 additions & 4 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { startRedis } from "./lib/server/db/redis";

export const init: ServerInit = async () => {
console.log("[SkyCrypt] Starting...");
const timeNow = performance.now();

await intializeNEURepository().then(async () => {
await intializeNEURepository().then(() => {
parseNEURepository();
});

await resourcesInit();

await startMongo()?.then(() => {
await startMongo().then(() => {
console.log("[MONGO] MongoDB successfully connected");

indexCollectons();
Expand All @@ -25,9 +26,9 @@ export const init: ServerInit = async () => {
console.log("[REDIS] Redis successfully connected");
});

await getPrices().then(() => {
await getPrices(true).then(() => {
console.log("[NETWORTH] Prices successfully fetched!");
});

console.log("[SkyCrypt] Started!");
console.log(`[SkyCrypt] Started in ${(performance.now() - timeNow).toFixed(2)}ms`);
};
5 changes: 1 addition & 4 deletions src/lib/server/constants/museum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function sortMuseumItems(museum: MuseumConstants, armorSetId: string) {
}

async function retrieveMuseumItems() {
const timeNow = Date.now();
// ! INFO: This is needed, the museum = { ... } doens't work for some reason?
// ! INFO: This is needed, the MUSEUM = { ... } doesn't work with vite reloading for some reason?
MUSEUM.armor_to_id = {};
MUSEUM.armor_sets = {};
MUSEUM.children = {};
Expand Down Expand Up @@ -65,8 +64,6 @@ async function retrieveMuseumItems() {
}
}
}

console.log(`[MUSEUM] Updated museum items in ${Date.now() - timeNow}ms`);
}

const MUSEUM: MuseumConstants = {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/server/constants/update-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import MONGO from "$lib/server/db/mongo";

export const COLLECTIONS = new Map<string, Collection>();

export async function updateCollections() {
export async function updateCollectionConstants() {
if (building) return;

const collections = await MONGO.collection("collections").findOne({});
if (collections?.collections == null) {
console.log(collections);
return;
}

Expand All @@ -21,7 +22,7 @@ export async function updateCollections() {
COLLECTIONS.set(category, collections.collections[category] as Collection);
}

console.log("[COLLECTIONS] Updated collections");
console.log("[COLLECTIONS] Updated collection constants");
}

setTimeout(updateCollections, 1000 * 60 * 60 * 12); // 12 hours
setTimeout(updateCollectionConstants, 1000 * 60 * 60 * 12); // 12 hours
2 changes: 1 addition & 1 deletion src/lib/server/constants/update-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function updateItemsConstants() {
ITEMS.set(skyblockItem.skyblock_id, skyblockItem);
}

console.log(`[ITEMS] Updated items in ${(Date.now() - timeNow).toLocaleString()}ms`);
console.log(`[ITEMS] Updated item constants in ${(Date.now() - timeNow).toLocaleString()}ms`);
}

setTimeout(updateItemsConstants, 1000 * 60 * 60 * 12); // 12 hours
7 changes: 3 additions & 4 deletions src/lib/server/custom_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,10 @@ async function loadResourcePacks() {
regex = mm.makeRe(regexString.substring(9), { nocase: true });
} else if (regexString.startsWith("pattern:")) {
if (regexString === "pattern:*" || regexString.trim() === "pattern:") {
texture.match = [];
break;
regex = new RegExp(".*");
} else {
regex = mm.makeRe(regexString.substring(9));
}

regex = mm.makeRe(regexString.substring(9));
} else if (regexString.startsWith("iregex:")) {
regex = new RegExp(regexString.substring(7), "i");
} else if (regexString.startsWith("regex:")) {
Expand Down
3 changes: 0 additions & 3 deletions src/lib/server/db/mongo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { building } from "$app/environment";
import { updateItemsConstants } from "$constants/update-items";
import { MONGO_DATABASE, MONGO_HOST, MONGO_PORT } from "$env/static/private";
import { MongoClient, type Db } from "mongodb";
import { updateCollections } from "./mongo/update-collections";
Expand All @@ -9,10 +8,8 @@ const client = !building ? new MongoClient(`mongodb://${MONGO_HOST}:${MONGO_PORT

export async function startMongo() {
if (building) return;
console.log("[MONGO] Starting mongo...");

await updateItems();
await updateItemsConstants();
await updateCollections();

return client?.connect() as Promise<MongoClient>;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/server/db/mongo/index-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import MONGO from "$lib/server/db/mongo";
export async function indexCollectons() {
if (building) return;

await MONGO.collection("emojis").createIndex({ uuid: 1 }, { unique: true });
if ((await MONGO.collection("emojis").indexExists("uuid_1")) === true) {
return;
}

await MONGO.collection("emojis").createIndex({ uuid: 1 }, { unique: true });
console.log("[MONGO] Collections indexed");
}
4 changes: 4 additions & 0 deletions src/lib/server/db/mongo/update-collections.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { building } from "$app/environment";
import { updateCollectionConstants } from "$constants/update-collections";
import type { Collection } from "$lib/server/constants/collections";
import MONGO from "../mongo";

Expand Down Expand Up @@ -32,6 +33,7 @@ export async function updateCollections() {

if (cache && cache.lastUpdated > Date.now() - cacheInternal) {
console.log(`[COLLECTIONS] Fetched collections in ${(Date.now() - timeNow).toLocaleString()}ms (cached)`);
await updateCollectionConstants();
return;
}

Expand Down Expand Up @@ -61,6 +63,8 @@ export async function updateCollections() {
await MONGO.collection("collections").updateOne({}, { $set: output }, { upsert: true });

console.log(`[COLLECTIONS] Fetched collections in ${(Date.now() - timeNow).toLocaleString()}ms`);

await updateCollectionConstants();
} catch (e) {
console.error(e);
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/server/db/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export const REDIS = createClient({
export async function startRedis() {
if (REDIS.isReady || REDIS.isOpen || building) return;

console.log("[REDIS] Starting redis...");
return REDIS.connect();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function intializeNEURepository() {
fs.mkdirSync("NotEnoughUpdates-REPO", { recursive: true });
}

if (dev) {
if (dev && !fs.existsSync("NotEnoughUpdates-REPO/.git")) {
console.log(`[NOT-ENOUGH-UPDATES] Initializing NEU repository.`);
try {
await simpleGit().submoduleUpdate(["--init", "--recursive"]);
Expand Down
11 changes: 2 additions & 9 deletions src/lib/server/helper/NotEnoughUpdates/updateNEURepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { building, dev } from "$app/environment";
import { building } from "$app/environment";
import fs from "node:fs";
import { simpleGit } from "simple-git";

Expand All @@ -19,14 +19,7 @@ export async function updateNotEnoughUpdatesRepository() {
if (diffSummary.files.length > 0) {
console.log(`[NOT-ENOUGH-UPDATES] Updating submodule...`);

// If dev, this is a valid submodule
if (dev) {
await gitSubmodule.submoduleUpdate(["--init", "--recursive"]);
await gitSubmodule.fetch();
} else {
// If not dev, this is just a normal cloned repository
await gitSubmodule.pull();
}
await gitSubmodule.pull();

console.log(`[NOT-ENOUGH-UPDATES] Updated submodule!`);
} else {
Expand Down

0 comments on commit 063b80b

Please sign in to comment.