Skip to content

Commit eaf0250

Browse files
committed
Save to caterva2
1 parent db7eec4 commit eaf0250

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- caterva2
78
pull_request:
89
branches:
910
- '*'

packages/contents/src/contents.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ export class Contents implements IContents {
398398
*/
399399
async save(path: string, options: Partial<IModel> = {}): Promise<IModel | null> {
400400
path = decodeURIComponent(path);
401+
//this.c2upload(path, options.content);
401402

402403
// process the file if coming from an upload
403404
const ext = PathExt.extname(options.name ?? '');
@@ -505,10 +506,20 @@ export class Contents implements IContents {
505506
item = { ...item, size: 0 };
506507
}
507508

508-
await (await this.storage).setItem(path, item);
509+
//await (await this.storage).setItem(path, item);
510+
this.c2upload(path, item.content);
509511
return item;
510512
}
511513

514+
async c2upload(path: string, content: object) {
515+
const filename = path.split('/').pop();
516+
const jsonstr = JSON.stringify(content);
517+
const blob = new Blob([jsonstr]);
518+
const formData = new FormData();
519+
formData.append('file', blob, filename);
520+
fetch(`/api/upload/${path}`, { method: 'POST', body: formData });
521+
}
522+
512523
/**
513524
* Delete a file from browser storage.
514525
*

0 commit comments

Comments
 (0)