File size: 981 Bytes
fac3250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from "fs";

const HF_TOKEN = process.env.HF_TOKEN;
const SECRET_CONFIG = fs.existsSync(".env.SECRET_CONFIG")
	? fs.readFileSync(".env.SECRET_CONFIG", "utf8")
	: process.env.SECRET_CONFIG;

if (SECRET_CONFIG === "") {
	throw new Error(
		"SECRET_CONFIG is not defined. Please provide it either in a file or as an environment variable."
	);
}

// Read the content of the file .env.template
const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");

// Prepend the content of the env variable SECRET_CONFIG
const full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;

// Make an HTTP POST request to add the space secre
fetch(`https://huggingface.co/api/spaces/huggingchat/chat-ui/secrets`, {
	method: "POST",
	body: JSON.stringify({
		key: "DOTENV_LOCAL",
		value: full_config,
		description: `Env variable for HuggingChat. Last updated ${new Date().toISOString()}`,
	}),
	headers: {
		Authorization: `Bearer ${HF_TOKEN}`,
		"Content-Type": "application/json",
	},
});