Spaces:
Running
Running
update deploy
Browse files- server.js +26 -4
- src/utils/consts.ts +1 -1
server.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from "path";
|
|
| 3 |
import { fileURLToPath } from "url";
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import cookieParser from "cookie-parser";
|
| 6 |
-
import { createRepo,
|
| 7 |
import { InferenceClient } from "@huggingface/inference";
|
| 8 |
import bodyParser from "body-parser";
|
| 9 |
|
|
@@ -107,7 +107,7 @@ app.post("/api/deploy", checkUser, async (req, res) => {
|
|
| 107 |
if (!path) {
|
| 108 |
newHtml = html.replace(
|
| 109 |
/<\/body>/,
|
| 110 |
-
`<p style="text-align: center; font-size: 12px; color: #
|
| 111 |
);
|
| 112 |
}
|
| 113 |
|
|
@@ -120,6 +120,9 @@ app.post("/api/deploy", checkUser, async (req, res) => {
|
|
| 120 |
type: "space",
|
| 121 |
name: path ?? "",
|
| 122 |
};
|
|
|
|
|
|
|
|
|
|
| 123 |
if (!path || path === "") {
|
| 124 |
const { name: username } = await whoAmI({ accessToken: hf_token });
|
| 125 |
const newTitle = title
|
|
@@ -136,10 +139,29 @@ app.post("/api/deploy", checkUser, async (req, res) => {
|
|
| 136 |
repo,
|
| 137 |
accessToken: hf_token,
|
| 138 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
}
|
| 140 |
-
await
|
| 141 |
repo,
|
| 142 |
-
|
| 143 |
accessToken: hf_token,
|
| 144 |
});
|
| 145 |
return res.status(200).send({ ok: true, path: repo.name });
|
|
|
|
| 3 |
import { fileURLToPath } from "url";
|
| 4 |
import dotenv from "dotenv";
|
| 5 |
import cookieParser from "cookie-parser";
|
| 6 |
+
import { createRepo, uploadFiles, whoAmI } from "@huggingface/hub";
|
| 7 |
import { InferenceClient } from "@huggingface/inference";
|
| 8 |
import bodyParser from "body-parser";
|
| 9 |
|
|
|
|
| 107 |
if (!path) {
|
| 108 |
newHtml = html.replace(
|
| 109 |
/<\/body>/,
|
| 110 |
+
`<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: absolute; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">This website has been generated by <a href="https://enzostvs-deepsite.hf.space" style="color: #fff;" target="_blank" >DeepSite</a> <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;"></p></body>`
|
| 111 |
);
|
| 112 |
}
|
| 113 |
|
|
|
|
| 120 |
type: "space",
|
| 121 |
name: path ?? "",
|
| 122 |
};
|
| 123 |
+
|
| 124 |
+
let readme;
|
| 125 |
+
|
| 126 |
if (!path || path === "") {
|
| 127 |
const { name: username } = await whoAmI({ accessToken: hf_token });
|
| 128 |
const newTitle = title
|
|
|
|
| 139 |
repo,
|
| 140 |
accessToken: hf_token,
|
| 141 |
});
|
| 142 |
+
readme = `---
|
| 143 |
+
title: ${newTitle}
|
| 144 |
+
emoji: 🚀
|
| 145 |
+
colorFrom: blue
|
| 146 |
+
colorTo: blue
|
| 147 |
+
sdk: static
|
| 148 |
+
pinned: false
|
| 149 |
+
tags:
|
| 150 |
+
- deepsite
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference`;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
const files = [file];
|
| 157 |
+
if (readme) {
|
| 158 |
+
const readmeFile = new Blob([readme], { type: "text/markdown" });
|
| 159 |
+
readmeFile.name = "README.md"; // Add name property to the Blob
|
| 160 |
+
files.push(readmeFile);
|
| 161 |
}
|
| 162 |
+
await uploadFiles({
|
| 163 |
repo,
|
| 164 |
+
files,
|
| 165 |
accessToken: hf_token,
|
| 166 |
});
|
| 167 |
return res.status(200).send({ ok: true, path: repo.name });
|
src/utils/consts.ts
CHANGED
|
@@ -41,7 +41,7 @@ export const defaultHTML = `<!DOCTYPE html>
|
|
| 41 |
<span>I'm ready to work,</span><br />
|
| 42 |
Ask me anything.
|
| 43 |
</h1>
|
| 44 |
-
<img src="/arrow.svg" class="arrow" />
|
| 45 |
<script></script>
|
| 46 |
</body>
|
| 47 |
</html>
|
|
|
|
| 41 |
<span>I'm ready to work,</span><br />
|
| 42 |
Ask me anything.
|
| 43 |
</h1>
|
| 44 |
+
<img src="https://enzostvs-test-enzo-lol.static.hf.space/arrow.svg" class="arrow" />
|
| 45 |
<script></script>
|
| 46 |
</body>
|
| 47 |
</html>
|