Spaces:
Running
Running
2410191345
Browse files- app.py +4 -11
- public/mmp4.zip +3 -0
- public/script.js +14 -24
app.py
CHANGED
|
@@ -20,7 +20,6 @@ app.add_middleware(
|
|
| 20 |
|
| 21 |
router = APIRouter()
|
| 22 |
processing = False
|
| 23 |
-
defaultZip = None
|
| 24 |
|
| 25 |
class TextRequest(BaseModel): text: str
|
| 26 |
|
|
@@ -60,22 +59,16 @@ async def load(zip_data: TextRequest):
|
|
| 60 |
|
| 61 |
@router.get('/check')
|
| 62 |
async def check():
|
| 63 |
-
global processing
|
| 64 |
-
return 'ng' if processing
|
| 65 |
-
|
| 66 |
-
@router.post('/zip')
|
| 67 |
-
async def zip(zip_data: TextRequest):
|
| 68 |
-
global defaultZip
|
| 69 |
-
defaultZip = BytesIO(base64.b64decode(zip_data.text))
|
| 70 |
-
return ''
|
| 71 |
|
| 72 |
@router.post('/sb3')
|
| 73 |
async def sb3(req_data: TextRequest):
|
| 74 |
-
global processing
|
| 75 |
if processing: return ''
|
| 76 |
processing = True
|
| 77 |
data = json.loads(req_data.text)
|
| 78 |
-
with zipfile.ZipFile(
|
| 79 |
with template_zip.open('project.json') as f:
|
| 80 |
project = json.loads(f.read().decode('utf-8'))
|
| 81 |
|
|
|
|
| 20 |
|
| 21 |
router = APIRouter()
|
| 22 |
processing = False
|
|
|
|
| 23 |
|
| 24 |
class TextRequest(BaseModel): text: str
|
| 25 |
|
|
|
|
| 59 |
|
| 60 |
@router.get('/check')
|
| 61 |
async def check():
|
| 62 |
+
global processing
|
| 63 |
+
return 'ng' if processing else 'ok'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
@router.post('/sb3')
|
| 66 |
async def sb3(req_data: TextRequest):
|
| 67 |
+
global processing
|
| 68 |
if processing: return ''
|
| 69 |
processing = True
|
| 70 |
data = json.loads(req_data.text)
|
| 71 |
+
with zipfile.ZipFile('app/public/mmp4.zip', 'r') as template_zip:
|
| 72 |
with template_zip.open('project.json') as f:
|
| 73 |
project = json.loads(f.read().decode('utf-8'))
|
| 74 |
|
public/mmp4.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5e79821c3e65e85abf1c6eb8a45cf9143d6844f15e2402f080cd06de018af428
|
| 3 |
+
size 11143447
|
public/script.js
CHANGED
|
@@ -160,35 +160,25 @@ const save = async () => {
|
|
| 160 |
const load = async () => {
|
| 161 |
const file = document.createElement(`input`);
|
| 162 |
file.type = `file`;
|
| 163 |
-
file.accept = `.mf4
|
| 164 |
file.click();
|
| 165 |
file.addEventListener(`change`, async () => {
|
| 166 |
const fileReader = new FileReader();
|
| 167 |
fileReader.addEventListener(`load`, async () => {
|
| 168 |
const base64Data = btoa(String.fromCharCode.apply(null, new Uint8Array(fileReader.result)));
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
.
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
});
|
| 183 |
-
} else if (file.files[0].name.endsWith(`.zip`)) {
|
| 184 |
-
if (confirm(`zip ファイルをセットします ( 管理者以外が行うと使えなくなる可能性があります )`)) {
|
| 185 |
-
await fetch(`/api/zip`, {
|
| 186 |
-
method: `post`,
|
| 187 |
-
headers: { 'Content-Type': 'application/json' },
|
| 188 |
-
body: JSON.stringify({ text: base64Data })
|
| 189 |
-
});
|
| 190 |
-
}
|
| 191 |
-
}
|
| 192 |
});
|
| 193 |
fileReader.readAsArrayBuffer(file.files[0]);
|
| 194 |
});
|
|
|
|
| 160 |
const load = async () => {
|
| 161 |
const file = document.createElement(`input`);
|
| 162 |
file.type = `file`;
|
| 163 |
+
file.accept = `.mf4`;
|
| 164 |
file.click();
|
| 165 |
file.addEventListener(`change`, async () => {
|
| 166 |
const fileReader = new FileReader();
|
| 167 |
fileReader.addEventListener(`load`, async () => {
|
| 168 |
const base64Data = btoa(String.fromCharCode.apply(null, new Uint8Array(fileReader.result)));
|
| 169 |
+
fetch(`/api/load`, {
|
| 170 |
+
method: `post`,
|
| 171 |
+
headers: { 'Content-Type': 'application/json' },
|
| 172 |
+
body: JSON.stringify({ text: base64Data })
|
| 173 |
+
})
|
| 174 |
+
.then(res => res.json())
|
| 175 |
+
.then(data => {
|
| 176 |
+
const dom = (new DOMParser()).parseFromString(data[0], `application/xml`);
|
| 177 |
+
workspace.clear();
|
| 178 |
+
Blockly.Xml.domToWorkspace(dom.documentElement, workspace);
|
| 179 |
+
costumes = data.slice(2, data.length);
|
| 180 |
+
reloadCos();
|
| 181 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
});
|
| 183 |
fileReader.readAsArrayBuffer(file.files[0]);
|
| 184 |
});
|