@esportsplus/web-storage 0.0.0 → 0.0.1
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/build/index.d.ts +1 -6
- package/build/index.js +2 -3
- package/package.json +30 -33
- package/src/index.ts +5 -6
- package/build/ipfs/index.d.ts +0 -6
- package/build/ipfs/index.js +0 -54
- package/build/ipfs/types.d.ts +0 -5
- package/build/ipfs/types.js +0 -1
- package/src/ipfs/index.ts +0 -74
- package/src/ipfs/types.ts +0 -4
package/build/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import ipfs from './ipfs';
|
|
2
1
|
import local from './local';
|
|
3
2
|
declare const _default: {
|
|
4
|
-
ipfs: {
|
|
5
|
-
upload: (data: import("./ipfs/types").Data, compress?: boolean | undefined) => Promise<string>;
|
|
6
|
-
uploadable: (value: any) => boolean;
|
|
7
|
-
};
|
|
8
3
|
local: {
|
|
9
4
|
clear: (callback?: ((err: any) => void) | undefined) => Promise<void>;
|
|
10
5
|
delete: (key: string) => void;
|
|
@@ -16,4 +11,4 @@ declare const _default: {
|
|
|
16
11
|
};
|
|
17
12
|
};
|
|
18
13
|
export default _default;
|
|
19
|
-
export {
|
|
14
|
+
export { local };
|
package/build/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "ICJR",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"@esportsplus/dot": "^0.0.3",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"types": "./build/index.d.ts",
|
|
32
|
-
"version": "0.0.0"
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"author": "ICJR",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@esportsplus/dot": "^0.0.3",
|
|
5
|
+
"localforage": "^1.10.0"
|
|
6
|
+
},
|
|
7
|
+
"description": "Web storage utility",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"glob": "^7.1.7",
|
|
10
|
+
"node-polyfill-webpack-plugin": "^1.1.4",
|
|
11
|
+
"npm-run-all": "^4.1.5",
|
|
12
|
+
"ts-loader": "^9.2.6",
|
|
13
|
+
"tsc-alias": "^1.5.0",
|
|
14
|
+
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
|
15
|
+
"typescript": "^4.5.2",
|
|
16
|
+
"webpack": "^5.64.4",
|
|
17
|
+
"webpack-cli": "^4.9.1"
|
|
18
|
+
},
|
|
19
|
+
"main": "./build/index.js",
|
|
20
|
+
"name": "@esportsplus/web-storage",
|
|
21
|
+
"private": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"-": "-",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"types": "./build/index.d.ts",
|
|
29
|
+
"version": "0.0.1"
|
|
30
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export { ipfs, local };
|
|
1
|
+
import local from './local';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export default { local };
|
|
5
|
+
export { local };
|
package/build/ipfs/index.d.ts
DELETED
package/build/ipfs/index.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import compressor from 'browser-image-compression';
|
|
2
|
-
import * as IPFS from 'ipfs-core';
|
|
3
|
-
let node;
|
|
4
|
-
async function connect() {
|
|
5
|
-
if (node) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
node = await IPFS.create();
|
|
9
|
-
}
|
|
10
|
-
;
|
|
11
|
-
const upload = async (data, compress) => {
|
|
12
|
-
let cid = '';
|
|
13
|
-
await connect();
|
|
14
|
-
if (Array.isArray(data)) {
|
|
15
|
-
for await (const item of node.addAll(data, {
|
|
16
|
-
pin: true,
|
|
17
|
-
wrapWithDirectory: true
|
|
18
|
-
})) {
|
|
19
|
-
if (item.path) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
cid = item.cid.toString();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
if (data instanceof File) {
|
|
27
|
-
if (data.type.startsWith('image') && compress) {
|
|
28
|
-
data = await compressor(data, { useWebWorker: true });
|
|
29
|
-
}
|
|
30
|
-
data = await data.text();
|
|
31
|
-
}
|
|
32
|
-
cid = (await node.add(data)).cid.toString();
|
|
33
|
-
}
|
|
34
|
-
return `ipfs://${cid}`;
|
|
35
|
-
};
|
|
36
|
-
const uploadable = (value) => {
|
|
37
|
-
let valid = false;
|
|
38
|
-
if (value instanceof File) {
|
|
39
|
-
valid = true;
|
|
40
|
-
}
|
|
41
|
-
else if (typeof value === 'object' && value !== null) {
|
|
42
|
-
valid = 'content' in value;
|
|
43
|
-
}
|
|
44
|
-
else if (Array.isArray(value)) {
|
|
45
|
-
for (let i = 0, n = value.length; i < n; i++) {
|
|
46
|
-
valid = uploadable(value[i]);
|
|
47
|
-
if (!valid) {
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return valid;
|
|
53
|
-
};
|
|
54
|
-
export default { upload, uploadable };
|
package/build/ipfs/types.d.ts
DELETED
package/build/ipfs/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/ipfs/index.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { Data } from './types';
|
|
2
|
-
import compressor from 'browser-image-compression';
|
|
3
|
-
import * as IPFS from 'ipfs-core';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let node: any;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// TODO: Enable custom IPFS host connections
|
|
10
|
-
async function connect(): Promise<void> {
|
|
11
|
-
if (node) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
node = await IPFS.create();
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const upload = async (data: Data, compress?: boolean): Promise<string> => {
|
|
20
|
-
let cid: string = '';
|
|
21
|
-
|
|
22
|
-
await connect();
|
|
23
|
-
|
|
24
|
-
if (Array.isArray(data)) {
|
|
25
|
-
for await (const item of node.addAll(data, {
|
|
26
|
-
pin: true,
|
|
27
|
-
wrapWithDirectory: true
|
|
28
|
-
})) {
|
|
29
|
-
if (item.path) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
cid = item.cid.toString();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
if (data instanceof File) {
|
|
38
|
-
if (data.type.startsWith('image') && compress) {
|
|
39
|
-
data = await compressor(data, { useWebWorker: true });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
data = await data.text();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
cid = ( await node.add(data) ).cid.toString();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return `ipfs://${cid}`;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const uploadable = (value: any): boolean => {
|
|
52
|
-
let valid = false;
|
|
53
|
-
|
|
54
|
-
if (value instanceof File) {
|
|
55
|
-
valid = true;
|
|
56
|
-
}
|
|
57
|
-
else if (typeof value === 'object' && value !== null) {
|
|
58
|
-
valid = 'content' in value;
|
|
59
|
-
}
|
|
60
|
-
else if (Array.isArray(value)) {
|
|
61
|
-
for (let i = 0, n = value.length; i < n; i++) {
|
|
62
|
-
valid = uploadable(value[i]);
|
|
63
|
-
|
|
64
|
-
if (!valid) {
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return valid;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
export default { upload, uploadable };
|
package/src/ipfs/types.ts
DELETED