file uploader
This commit is contained in:
@@ -3,7 +3,6 @@ import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
const eulaRegex = /(eula=false)/;
|
||||
export const checkEULA = (instance = "server") =>
|
||||
!IS_BROWSER && !eulaRegex.test(Deno.readTextFileSync(`./${instance}/eula.txt`));
|
||||
// true;
|
||||
|
||||
export const acceptEULA = (instance = "server") => {
|
||||
const eula = Deno.readTextFileSync(`./${instance}/eula.txt`);
|
||||
|
@@ -1,7 +1,10 @@
|
||||
import { ensureFileSync } from "$std/fs/ensure_file.ts";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
import { MCGrizzConf } from "../types/mcgrizzconf.ts";
|
||||
|
||||
const defaultConf: MCGrizzConf = {
|
||||
loader: 'unset',
|
||||
version: ''
|
||||
}
|
||||
|
||||
const confPath = 'mcgrizz.json'
|
||||
@@ -14,7 +17,9 @@ export function makeConfFile(): MCGrizzConf {
|
||||
}
|
||||
|
||||
export function getConfFile(): MCGrizzConf {
|
||||
const conf = JSON.parse(Deno.readTextFileSync(confPath));
|
||||
if (IS_BROWSER) return defaultConf;
|
||||
ensureFileSync(confPath);
|
||||
const conf = JSON.parse(Deno.readTextFileSync(confPath) || 'null');
|
||||
|
||||
if (!conf) {
|
||||
return makeConfFile();
|
||||
@@ -24,7 +29,8 @@ export function getConfFile(): MCGrizzConf {
|
||||
}
|
||||
|
||||
export async function updateConfFile(newConf: Partial<MCGrizzConf>) {
|
||||
const conf = {...getConfFile(), newConf};
|
||||
if (IS_BROWSER) return;
|
||||
const conf = {...getConfFile(), ...newConf};
|
||||
|
||||
await Deno.writeTextFile(confPath, JSON.stringify(conf, null, 2));
|
||||
}
|
||||
|
35
util/download.ts
Normal file
35
util/download.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { ensureFile } from "$std/fs/ensure_file.ts";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param src url of file
|
||||
* @param dest destination file. If `useFileName` is true, this should be the destination directory
|
||||
* @param [useFileName] whether to use the inferred file name from `src`
|
||||
*/
|
||||
|
||||
export async function downloadFile(src: string, dest: string, useFileName?:boolean) {
|
||||
if (!(src.startsWith("http://") || src.startsWith("https://"))) {
|
||||
throw new TypeError("URL must start with be http:// or https://");
|
||||
}
|
||||
|
||||
const fileName = src.split('/').at(-1);
|
||||
|
||||
const resp = await fetch(src);
|
||||
if (!resp.ok) {
|
||||
throw new Deno.errors.BadResource(
|
||||
`Request failed with status ${resp.status}`,
|
||||
);
|
||||
} else if (!resp.body) {
|
||||
throw new Deno.errors.UnexpectedEof(
|
||||
`The download url ${src} doesn't contain a file to download`,
|
||||
);
|
||||
} else if (resp.status === 404) {
|
||||
throw new Deno.errors.NotFound(
|
||||
`The requested url "${src}" could not be found`,
|
||||
);
|
||||
}
|
||||
|
||||
await ensureFile(useFileName ? dest + fileName : dest);
|
||||
const file = await Deno.open(dest, { truncate: true, write: true });
|
||||
resp.body.pipeTo(file.writable);
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
// deno-lint-ignore-file no-fallthrough
|
||||
import { MCGrizzConf } from "../types/mcgrizzconf.ts";
|
||||
import { NavItem } from "../types/nav.ts";
|
||||
import { makeConfFile } from "./confFile.ts";
|
||||
@@ -13,16 +14,20 @@ export function getNavItems(): NavItem[] {
|
||||
conf = makeConfFile();
|
||||
}
|
||||
|
||||
const items: NavItem[] = [];
|
||||
|
||||
switch (conf.loader) {
|
||||
case "unset":
|
||||
return [{
|
||||
items.push({
|
||||
title: "Setup",
|
||||
href: "/",
|
||||
}];
|
||||
});
|
||||
break;
|
||||
case "forge":
|
||||
case "fabric":
|
||||
items.push({ title: "Mods", href: "/mods" });
|
||||
case "vanilla":
|
||||
return [
|
||||
items.unshift(
|
||||
{
|
||||
title: "Server Terminal",
|
||||
href: "/terminal",
|
||||
@@ -35,6 +40,8 @@ export function getNavItems(): NavItem[] {
|
||||
title: "Server Properties",
|
||||
href: "/properties",
|
||||
},
|
||||
];
|
||||
);
|
||||
break;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { ensureFile } from "$std/fs/ensure_file.ts";
|
||||
import { SERVER_STATE } from "../state/serverState.ts";
|
||||
import { filterTruthy } from "./filters.ts";
|
||||
|
||||
@@ -30,7 +31,7 @@ export const getPlayerData = async (username: string) => {
|
||||
username = username.trim();
|
||||
if (!username) return;
|
||||
const cacheFile = 'players.cache.json'
|
||||
await Deno.create(cacheFile);
|
||||
await ensureFile(cacheFile);
|
||||
const cache = JSON.parse(await Deno.readTextFile(cacheFile) || '{}');
|
||||
if (!cache[username]) {
|
||||
const req = await fetch('https://playerdb.co/api/player/minecraft/' + username, {
|
||||
|
Reference in New Issue
Block a user