@social-mail/social-mail-client 1.2.40 → 1.2.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-client",
3
- "version": "1.2.40",
3
+ "version": "1.2.41",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,11 +4,21 @@ import XNode from "@web-atoms/core/dist/core/XNode";
4
4
  import Action from "@web-atoms/core/dist/view-model/Action";
5
5
  import { UMD } from "@web-atoms/core/dist/core/types";
6
6
  import FetchBuilder from "@web-atoms/core/dist/services/FetchBuilder";
7
+ import { Inject } from "@web-atoms/core/dist/di/Inject";
8
+ import InjectProperty from "@web-atoms/core/dist/core/InjectProperty";
9
+ import CloudFileService from "../../../../web/page/files/service/CloudFileService";
10
+ import MimeTypeService from "../../../../services/files/MimeTypeService";
7
11
 
8
12
  export default class ChooseWebSiteTemplatePage extends PopupWindowPage {
9
13
 
10
14
  parameters: IAppFile;
11
15
 
16
+ @InjectProperty
17
+ cloudFileService: CloudFileService;
18
+
19
+ @InjectProperty
20
+ mimeTypeService: MimeTypeService;
21
+
12
22
  async init() {
13
23
  this.renderer = <div>
14
24
  <button
@@ -24,18 +34,23 @@ export default class ChooseWebSiteTemplatePage extends PopupWindowPage {
24
34
 
25
35
  // upload
26
36
  await this.upload("index.html", template);
27
- await this.upload("styles/vars.css", template);
37
+ await this.upload("vars.css", template, "styles");
28
38
  }
29
39
 
30
- async upload(fileName: string, template) {
40
+ async upload(fileName, template, folder = void 0) {
31
41
 
32
- const path = UMD.resolvePath(`@social-mail/social-mail-client/content/templates/${template}/${fileName}`);
42
+ const templatePath = folder ? `${folder}/${fileName}` : fileName;
43
+ const path = UMD.resolvePath(`@social-mail/social-mail-client/content/templates/${template}/${templatePath}`);
33
44
  const content = await FetchBuilder.get(path).responseAsText();
34
45
 
35
- const url = `/api/upload?parentID=${this.parameters.appFileID}`;
36
- const body = new FormData();
37
- body.append(fileName, new Blob([content], { type: "text/html"}), fileName);
38
- const rs = await fetch(url, { method: "POST", body });
46
+ const contentType = await this.mimeTypeService.getMimeType(fileName);
47
+
48
+ await this.cloudFileService.saveFile({
49
+ content: new File([content], fileName, { type: contentType }),
50
+ parentID: this.parameters.appFileID,
51
+ folder
52
+ });
53
+
39
54
  }
40
55
 
41
56
  }
@@ -0,0 +1,45 @@
1
+ import DISingleton from "@web-atoms/core/dist/di/DISingleton";
2
+ import FetchBuilder from "@web-atoms/core/dist/services/FetchBuilder";
3
+
4
+ export interface IMimeMap {
5
+ [key: string]: {
6
+ extensions?: string[]
7
+ }
8
+ }
9
+
10
+ let mimeMap = void 0 as Promise<Map<string,string>>;
11
+
12
+ @DISingleton()
13
+ export default class MimeTypeService {
14
+
15
+ async getMimeType(fileName: string) {
16
+ mimeMap ??= this.createMap();
17
+ const map = await mimeMap;
18
+ const group = /\.([^\.]+)$/.exec(fileName);
19
+ if (group) {
20
+ const ct = map.get(group[1]);
21
+ if (ct) {
22
+ return ct;
23
+ }
24
+ }
25
+ return "application/octat-stream";
26
+ }
27
+
28
+ async createMap(): Promise<Map<string, string>> {
29
+ const json = await FetchBuilder.get("https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json").responseAsJson<IMimeMap>();
30
+ const map = new Map<string,string>();
31
+ setTimeout(() => mimeMap = null, 60000);
32
+ for (const key in json) {
33
+ if (Object.prototype.hasOwnProperty.call(json, key)) {
34
+ const { extensions } = json[key];
35
+ if (extensions) {
36
+ for (const iterator of extensions) {
37
+ map.set(iterator, key);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ return map;
43
+ }
44
+
45
+ }