esoftplay 0.0.267 → 0.0.268-04cfb21

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.
@@ -1,4 +1,7 @@
1
1
  // noPage
2
+
3
+ import { createMMKV } from "react-native-mmkv";
4
+
2
5
  // withObject
3
6
  let storage: any;
4
7
  let isWeb = typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
@@ -19,8 +22,7 @@ if (isWeb) {
19
22
  }
20
23
  } else {
21
24
  // @ts-ignore
22
- const MMKV = require('react-native-mmkv').MMKV;
23
- storage = new MMKV();
25
+ storage = createMMKV()
24
26
  }
25
27
 
26
28
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md) untuk melihat dokumentasi*/
@@ -39,7 +41,7 @@ const FastStorage = {
39
41
  },
40
42
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md#removeItem) untuk melihat dokumentasi*/
41
43
  removeItem(key: string) {
42
- storage.delete(key)
44
+ storage.remove(key)
43
45
  },
44
46
  /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md#clear) untuk melihat dokumentasi*/
45
47
  clear(): void {
@@ -1,90 +1,119 @@
1
1
  //noPage
2
- import * as FileSystem from 'expo-file-system';
2
+ import { Directory, File, Paths } from "expo-file-system";
3
3
 
4
- const CACHE_DIR = `${FileSystem.cacheDirectory}lib-storage-cache/`;
4
+ const CACHE_DIR = new Directory(Paths.cache, "lib-storage-cache");
5
5
 
6
6
  (async () => {
7
7
  try {
8
- await FileSystem.makeDirectoryAsync(CACHE_DIR);
9
- } catch (e) {
10
- // do nothing
11
- }
8
+ if (!CACHE_DIR.exists) {
9
+ CACHE_DIR.create();
10
+ }
11
+ } catch { }
12
12
  })();
13
13
 
14
14
  const Storage = {
15
- getDBPath(key: string): string {
16
- const path = `${CACHE_DIR}${key.replace(/\//g, "-")}.txt`;
17
- return path;
15
+ getDBPath(key: string): File {
16
+ const name = key.replace(/\//g, "-") + ".txt";
17
+ return new File(CACHE_DIR, name);
18
18
  },
19
- async getItem(key: string): Promise<string | null> {
20
- const path = this.getDBPath(key);
19
+
20
+ async getItem(key: string): Promise<any | null> {
21
21
  try {
22
- const info = await FileSystem.getInfoAsync(path);
23
- const { exists } = info;
24
- if (exists) {
25
- const value = await FileSystem.readAsStringAsync(path, { encoding: 'utf8' });
26
- return JSON.parse(value);
27
- }
28
- } catch (error) {
22
+ const file = this.getDBPath(key);
23
+
24
+ if (!file.exists) return null;
25
+
26
+ const value = await file.text();
27
+ return JSON.parse(value);
28
+ } catch {
29
29
  return null;
30
30
  }
31
- return null;
32
31
  },
32
+
33
33
  async setItem(key: string, value: string): Promise<string> {
34
- const path = this.getDBPath(key);
35
- await FileSystem.writeAsStringAsync(path, value, { encoding: 'utf8' });
34
+ const file = this.getDBPath(key);
35
+
36
+ await file.write(value);
37
+
36
38
  return value;
37
39
  },
40
+
38
41
  async removeItem(key: string): Promise<string> {
39
- const path = this.getDBPath(key);
40
42
  try {
41
- await FileSystem.deleteAsync(path);
42
- } catch (error) { }
43
+ const file = this.getDBPath(key);
44
+
45
+ if (file.exists) {
46
+ file.delete();
47
+ }
48
+ } catch { }
49
+
43
50
  return key;
44
51
  },
52
+
45
53
  clear(): void {
46
- FileSystem.deleteAsync(CACHE_DIR);
54
+ try {
55
+ if (CACHE_DIR.exists) {
56
+ CACHE_DIR.delete();
57
+ }
58
+ } catch { }
47
59
  },
48
- async sendTelegram(key: string, message: string, onDone?: () => void, onFailed?: (reason: string) => void, chat_id?: string, customFileName?: (originalName: string) => string,) {
49
60
 
61
+ async sendTelegram(
62
+ key: string,
63
+ message: string,
64
+ onDone?: () => void,
65
+ onFailed?: (reason: string) => void,
66
+ chat_id?: string,
67
+ customFileName?: (originalName: string) => string
68
+ ) {
50
69
  try {
51
- let dbPath = Storage.getDBPath(key)
52
- let fileInfo = await FileSystem.getInfoAsync(dbPath, {});
53
- if (!fileInfo.exists) {
54
- onFailed?.("File not found")
55
- return
70
+ const file = this.getDBPath(key);
71
+
72
+ if (!file.exists) {
73
+ onFailed?.("File not found");
74
+ return;
56
75
  }
57
76
 
58
- const fileName = fileInfo?.uri?.split('/').pop();
77
+ const fileName = file.name;
59
78
 
60
79
  if (fileName) {
61
- var parts = fileName.split('.');
62
- var fileWithoutExtension = parts.slice(0, -1).join('.');
63
- var extension = parts[parts.length - 1];
80
+ const parts = fileName.split(".");
81
+ const fileWithoutExtension = parts.slice(0, -1).join(".");
82
+ const extension = parts[parts.length - 1];
83
+
64
84
  const formData = new FormData();
65
- formData.append('caption', message);
66
- formData.append('chat_id', chat_id ?? '-1001737180019');
67
- formData.append('document', {
68
- uri: dbPath,
69
- name: (customFileName?.(fileWithoutExtension) || fileWithoutExtension) + "." + extension,
70
- type: 'text/csv',
71
- });
72
- const response = await fetch(`https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendDocument`, {
73
- method: 'POST',
74
- body: formData,
75
- });
85
+ formData.append("caption", message);
86
+ formData.append("chat_id", chat_id ?? "-1001737180019");
87
+
88
+ formData.append("document", {
89
+ uri: file.uri,
90
+ name:
91
+ (customFileName?.(fileWithoutExtension) || fileWithoutExtension) +
92
+ "." +
93
+ extension,
94
+ type: "text/csv",
95
+ } as any);
96
+
97
+ const response = await fetch(
98
+ `https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendDocument`,
99
+ {
100
+ method: "POST",
101
+ body: formData,
102
+ }
103
+ );
76
104
 
77
105
  const result = await response.json();
78
- if (result.ok == true) {
79
- onDone?.()
106
+
107
+ if (result.ok === true) {
108
+ onDone?.();
80
109
  } else {
81
- onFailed?.(result)
110
+ onFailed?.(JSON.stringify(result));
82
111
  }
83
112
  }
84
113
  } catch (ex) {
85
- onFailed?.(String(ex))
114
+ onFailed?.(String(ex));
86
115
  }
87
- }
88
- }
116
+ },
117
+ };
89
118
 
90
- export default Storage;
119
+ export default Storage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.267",
3
+ "version": "0.0.268-04cfb21",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",
package/publisher.js CHANGED
@@ -2,14 +2,10 @@ const shell = require('child_process').execSync;
2
2
  const packJson = require("./package.json")
3
3
  const fs = require('fs');
4
4
  const version = packJson.version
5
- const vm = version.match(/([a-z])/g)
6
- const letter = vm ? vm[0] : null
7
- const number = version.replace(/-/g, "").replace(letter, "")
8
- let nextNumber = number.split(".")[2]
9
- let nextVersion = number.split(".")[0] + "." + number.split(".")[1] + "."
10
-
11
- nextNumber = Number(nextNumber) + 1
12
- nextVersion += nextNumber
5
+ const baseVersion = version.split('-')[0]
6
+ const parts = baseVersion.split('.')
7
+ let nextNumber = parseInt(parts[2]) + 1
8
+ let nextVersion = parts[0] + '.' + parts[1] + '.' + nextNumber
13
9
  const newPackJson = { ...packJson, version: nextVersion }
14
10
  fs.writeFileSync("./package.json", JSON.stringify(newPackJson, undefined, 2))
15
11
  shell("npm publish", { stdio: ['inherit', 'inherit', 'inherit'] })
@@ -0,0 +1,12 @@
1
+ const shell = require('child_process').execSync;
2
+ const packJson = require("./package.json")
3
+ const fs = require('fs');
4
+ const crypto = require('crypto')
5
+ const version = packJson.version
6
+ const baseVersion = version.split('-')[0]
7
+ const randomHash = crypto.randomBytes(4).toString('hex').substring(0,7)
8
+ const nextVersion = baseVersion + '-' + randomHash
9
+ const newPackJson = { ...packJson, version: nextVersion }
10
+ fs.writeFileSync("./package.json", JSON.stringify(newPackJson, undefined, 2))
11
+ shell("npm publish", { stdio: ['inherit', 'inherit', 'inherit'] })
12
+ console.log("\nbun add esoftplay@" + nextVersion + " && bun install\n")