Move public assets to stable paths
This commit is contained in:
@@ -1,21 +1,73 @@
|
||||
import {createClient} from '@supabase/supabase-js';
|
||||
import {createHash,randomBytes} from 'node:crypto';
|
||||
import {mkdir,readFile,writeFile} from 'node:fs/promises';
|
||||
import {existsSync} from 'node:fs';
|
||||
process.loadEnvFile('.env.local');
|
||||
const client=createClient(process.env.NEXT_PUBLIC_SUPABASE_URL!,process.env.SUPABASE_SECRET_KEY!,{auth:{persistSession:false}});
|
||||
function check<T>(r:{data:T,error:{message:string}|null}):NonNullable<T>{if(r.error)throw new Error(r.error.message);return r.data!;}
|
||||
await mkdir('.data',{recursive:true});
|
||||
if(!existsSync('.data/test-account.json')){
|
||||
const password=randomBytes(32).toString('hex'),token='mg_'+randomBytes(32).toString('hex'),email='minegeo-fixture-'+randomBytes(4).toString('hex')+'@example.com';
|
||||
const {user}=check(await client.auth.admin.createUser({email,password,email_confirm:true}));if(!user)throw new Error('No fixture account returned');
|
||||
check(await client.from('profiles').insert({id:user.id,display_name:'MineGeo test world',role:'moderator'}));
|
||||
check(await client.from('contributor_tokens').insert({owner_id:user.id,token_hash:createHash('sha256').update(token).digest('hex'),label:'Local integration fixture'}));
|
||||
await writeFile('.data/test-account.json',JSON.stringify({id:user.id,email,password,token}));
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { existsSync } from "node:fs";
|
||||
process.loadEnvFile(".env.local");
|
||||
const client = createClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.SUPABASE_SECRET_KEY!,
|
||||
{ auth: { persistSession: false } },
|
||||
);
|
||||
function check<T>(r: {
|
||||
data: T;
|
||||
error: { message: string } | null;
|
||||
}): NonNullable<T> {
|
||||
if (r.error) throw new Error(r.error.message);
|
||||
return r.data!;
|
||||
}
|
||||
const manifest=JSON.parse(await readFile('.cache/paper-proof/plugins/MineGeo/export/manifest.json','utf8'));
|
||||
manifest.name='The First Expedition';manifest.serverName='MineGeo Test World';manifest.description='A real Paper 1.21.11 renderer test world: terrain, water and a builder’s outpost. Exported with no connected capture player. This small map is for trying MineGeo.';
|
||||
await mkdir('.data/proof-upload',{recursive:true});
|
||||
await writeFile('.data/proof-upload/manifest.json',JSON.stringify(manifest));
|
||||
await writeFile('.data/proof-upload/terrain.json.gz',await readFile('.cache/paper-proof/plugins/MineGeo/export/terrain.json.gz'));
|
||||
console.log('Fixture contributor and real Paper upload are ready. Credentials remain in ignored local files.');
|
||||
await mkdir(".data", { recursive: true });
|
||||
if (!existsSync(".data/test-account.json")) {
|
||||
const password = randomBytes(32).toString("hex"),
|
||||
token = "mg_" + randomBytes(32).toString("hex"),
|
||||
email =
|
||||
"minegeo-fixture-" + randomBytes(4).toString("hex") + "@example.com";
|
||||
const created = await client.auth.admin.createUser({
|
||||
email,
|
||||
password,
|
||||
email_confirm: true,
|
||||
});
|
||||
if (created.error) throw new Error(created.error.message);
|
||||
const user = created.data.user;
|
||||
if (!user) throw new Error("No fixture account returned");
|
||||
check(
|
||||
await client
|
||||
.from("profiles")
|
||||
.insert({
|
||||
id: user.id,
|
||||
display_name: "MineGeo test world",
|
||||
role: "moderator",
|
||||
}),
|
||||
);
|
||||
check(
|
||||
await client
|
||||
.from("contributor_tokens")
|
||||
.insert({
|
||||
owner_id: user.id,
|
||||
token_hash: createHash("sha256").update(token).digest("hex"),
|
||||
label: "Local integration fixture",
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
".data/test-account.json",
|
||||
JSON.stringify({ id: user.id, email, password, token }),
|
||||
);
|
||||
}
|
||||
const manifest = JSON.parse(
|
||||
await readFile(
|
||||
".cache/paper-proof/plugins/MineGeo/export/manifest.json",
|
||||
"utf8",
|
||||
),
|
||||
);
|
||||
manifest.name = "The First Expedition";
|
||||
manifest.serverName = "MineGeo Test World";
|
||||
manifest.description =
|
||||
"A real Paper 1.21.11 renderer test world: terrain, water and a builder’s outpost. Exported with no connected capture player. This small map is for trying MineGeo.";
|
||||
await mkdir(".data/proof-upload", { recursive: true });
|
||||
await writeFile(".data/proof-upload/manifest.json", JSON.stringify(manifest));
|
||||
await writeFile(
|
||||
".data/proof-upload/terrain.json.gz",
|
||||
await readFile(".cache/paper-proof/plugins/MineGeo/export/terrain.json.gz"),
|
||||
);
|
||||
console.log(
|
||||
"Fixture contributor and real Paper upload are ready. Credentials remain in ignored local files.",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user