@roadmanjs/firebase-admin 0.0.24 → 0.0.25
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/dist/client/gql/media.fragment.d.ts +3 -0
- package/dist/client/gql/media.fragment.js +3 -0
- package/dist/client/gql/media.fragment.js.map +1 -1
- package/dist/client/gql/media.mutation.d.ts +2 -0
- package/dist/client/gql/media.mutation.js +18 -1
- package/dist/client/gql/media.mutation.js.map +1 -1
- package/dist/media/media.methods.d.ts +15 -0
- package/dist/media/media.methods.js +32 -1
- package/dist/media/media.methods.js.map +1 -1
- package/dist/media/media.model.d.ts +3 -0
- package/dist/media/media.model.js +12 -0
- package/dist/media/media.model.js.map +1 -1
- package/dist/media/media.resolver.fastdfs.d.ts +7 -0
- package/dist/media/media.resolver.fastdfs.js +163 -0
- package/dist/media/media.resolver.fastdfs.js.map +1 -0
- package/dist/roadman.d.ts +3 -1
- package/dist/roadman.js +8 -1
- package/dist/roadman.js.map +1 -1
- package/package.json +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.fragment.js","sourceRoot":"","sources":["../../../src/client/gql/media.fragment.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;
|
|
1
|
+
{"version":3,"file":"media.fragment.js","sourceRoot":"","sources":["../../../src/client/gql/media.fragment.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;AAuBjB,QAAA,qBAAqB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;CAavC,CAAC"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare const UPLOAD_FILES_MUTATION: import("graphql").DocumentNode;
|
|
2
2
|
export declare const UPLOAD_STRING_FILES_MUTATION: import("graphql").DocumentNode;
|
|
3
|
+
export declare const UPLOAD_FILES_FASTDFS_MUTATION: import("graphql").DocumentNode;
|
|
4
|
+
export declare const UPLOAD_STRING_FILES_FASTDFS_MUTATION: import("graphql").DocumentNode;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UPLOAD_STRING_FILES_MUTATION = exports.UPLOAD_FILES_MUTATION = void 0;
|
|
6
|
+
exports.UPLOAD_STRING_FILES_FASTDFS_MUTATION = exports.UPLOAD_FILES_FASTDFS_MUTATION = exports.UPLOAD_STRING_FILES_MUTATION = exports.UPLOAD_FILES_MUTATION = void 0;
|
|
7
7
|
const media_fragment_1 = require("./media.fragment");
|
|
8
8
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
9
9
|
exports.UPLOAD_FILES_MUTATION = (0, graphql_tag_1.default) `
|
|
@@ -22,4 +22,21 @@ exports.UPLOAD_STRING_FILES_MUTATION = (0, graphql_tag_1.default) `
|
|
|
22
22
|
}
|
|
23
23
|
${media_fragment_1.MediaDataTypeFragment}
|
|
24
24
|
`;
|
|
25
|
+
// FASTDFS
|
|
26
|
+
exports.UPLOAD_FILES_FASTDFS_MUTATION = (0, graphql_tag_1.default) `
|
|
27
|
+
mutation UploadFilesFastdfs($owner: String, $files: [Upload!]!) {
|
|
28
|
+
data: uploadFastdfs(owner: $owner, files: $files) {
|
|
29
|
+
...MediaDataTypeFragment
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
${media_fragment_1.MediaDataTypeFragment}
|
|
33
|
+
`;
|
|
34
|
+
exports.UPLOAD_STRING_FILES_FASTDFS_MUTATION = (0, graphql_tag_1.default) `
|
|
35
|
+
mutation UploadStringFilesFastdfs($owner: String, $files: [FileStringInput!]!) {
|
|
36
|
+
data: uploadStringFastdfs(owner: $owner, files: $files) {
|
|
37
|
+
...MediaDataTypeFragment
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
${media_fragment_1.MediaDataTypeFragment}
|
|
41
|
+
`;
|
|
25
42
|
//# sourceMappingURL=media.mutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.mutation.js","sourceRoot":"","sources":["../../../src/client/gql/media.mutation.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAuD;AACvD,8DAA8B;AAEjB,QAAA,qBAAqB,GAAG,IAAA,qBAAG,EAAA;;;;;;MAMlC,sCAAqB;CAC1B,CAAC;AAEW,QAAA,4BAA4B,GAAG,IAAA,qBAAG,EAAA;;;;;;MAMzC,sCAAqB;CAC1B,CAAC"}
|
|
1
|
+
{"version":3,"file":"media.mutation.js","sourceRoot":"","sources":["../../../src/client/gql/media.mutation.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAuD;AACvD,8DAA8B;AAEjB,QAAA,qBAAqB,GAAG,IAAA,qBAAG,EAAA;;;;;;MAMlC,sCAAqB;CAC1B,CAAC;AAEW,QAAA,4BAA4B,GAAG,IAAA,qBAAG,EAAA;;;;;;MAMzC,sCAAqB;CAC1B,CAAC;AAEF,UAAU;AACG,QAAA,6BAA6B,GAAG,IAAA,qBAAG,EAAA;;;;;;MAM1C,sCAAqB;CAC1B,CAAC;AAEW,QAAA,oCAAoC,GAAG,IAAA,qBAAG,EAAA;;;;;;MAMjD,sCAAqB;CAC1B,CAAC"}
|
|
@@ -1 +1,16 @@
|
|
|
1
1
|
export declare function uploadFileToBucket(filePath: string, fileDest: string, contentType?: string): Promise<string>;
|
|
2
|
+
interface UploadFileToFastdfs {
|
|
3
|
+
domain: string;
|
|
4
|
+
md5: string;
|
|
5
|
+
mtime: number;
|
|
6
|
+
path: string;
|
|
7
|
+
retcode: number;
|
|
8
|
+
retmsg: string;
|
|
9
|
+
scene: string;
|
|
10
|
+
scenes: string;
|
|
11
|
+
size: number;
|
|
12
|
+
src: string;
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const uploadFileToFastdfs: (filePath: string, fileDest: string) => Promise<UploadFileToFastdfs>;
|
|
16
|
+
export {};
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadFileToBucket = void 0;
|
|
6
|
+
exports.uploadFileToFastdfs = exports.uploadFileToBucket = void 0;
|
|
4
7
|
const firebase_1 = require("../firebase");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
5
10
|
const logs_1 = require("@roadmanjs/logs");
|
|
11
|
+
const request_1 = __importDefault(require("request"));
|
|
12
|
+
// const requests = promisify(request);
|
|
6
13
|
async function uploadFileToBucket(filePath, fileDest, contentType = 'image/png') {
|
|
7
14
|
const { projectId, storage: adminStorage } = await (0, firebase_1.configureFirebase)();
|
|
8
15
|
const storage = adminStorage();
|
|
@@ -34,4 +41,28 @@ async function uploadFileToBucket(filePath, fileDest, contentType = 'image/png')
|
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
exports.uploadFileToBucket = uploadFileToBucket;
|
|
44
|
+
const uploadFileToFastdfs = (filePath, fileDest) => new Promise((resolve, reject) => {
|
|
45
|
+
const fastdfsServer = process.env.FASTDFS_SERVER + '/group1/upload';
|
|
46
|
+
if ((0, lodash_1.isEmpty)(fastdfsServer)) {
|
|
47
|
+
return reject('FASTDFS_SERVER is not defined');
|
|
48
|
+
}
|
|
49
|
+
const req = request_1.default.post(fastdfsServer, function (err, resp, body) {
|
|
50
|
+
if (err) {
|
|
51
|
+
return reject(err);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const { data } = JSON.parse(body);
|
|
55
|
+
return resolve(data);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
return reject(err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const form = req.form();
|
|
62
|
+
form.append('scene', 'default');
|
|
63
|
+
form.append('output', 'json2');
|
|
64
|
+
form.append('filename', fileDest);
|
|
65
|
+
form.append('file', fs_1.default.createReadStream(filePath));
|
|
66
|
+
});
|
|
67
|
+
exports.uploadFileToFastdfs = uploadFileToFastdfs;
|
|
37
68
|
//# sourceMappingURL=media.methods.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.methods.js","sourceRoot":"","sources":["../../src/media/media.methods.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"media.methods.js","sourceRoot":"","sources":["../../src/media/media.methods.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA8C;AAC9C,4CAAoB;AACpB,mCAA+B;AAC/B,0CAAoC;AACpC,sDAA8B;AAC9B,uCAAuC;AAEhC,KAAK,UAAU,kBAAkB,CACpC,QAAgB,EAChB,QAAgB,EAChB,WAAW,GAAG,WAAW;IAEzB,MAAM,EAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAC,GAAG,MAAM,IAAA,4BAAiB,GAAE,CAAC;IACrE,MAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAE/B,MAAM,UAAU,GAAG,GAAG,SAAS,cAAc,CAAC;IAE9C,6FAA6F;IAE7F,qCAAqC;IACrC,IAAI;QACA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC1B,MAAM,EAAE,IAAI;YACZ,WAAW,EAAE,QAAQ;YACrB,sEAAsE;YACtE,wCAAwC;YACxC,QAAQ,EAAE;gBACN,WAAW;gBACX,yCAAyC;gBACzC,yDAAyD;gBACzD,YAAY,EAAE,UAAU;gBACxB,4CAA4C;aAC/C;SACJ,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,kCAAkC,UAAU,IAAI,QAAQ,EAAE,CAAC;QAC7E,IAAA,UAAG,EAAC,iBAAiB,SAAS,EAAE,CAAC,CAAC;QAClC,OAAO,SAA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AAC;AA1BM,QAAA,mBAAmB,uBA0BzB"}
|
|
@@ -29,6 +29,18 @@ __decorate([
|
|
|
29
29
|
__decorate([
|
|
30
30
|
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
31
31
|
], MediaDataType.prototype, "encoding", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, couchset_1.Field)(() => String, {
|
|
34
|
+
nullable: true,
|
|
35
|
+
description: 'The server where the file is stored, e.g fastdfs',
|
|
36
|
+
})
|
|
37
|
+
], MediaDataType.prototype, "server", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, couchset_1.Field)(() => Number, { nullable: true })
|
|
40
|
+
], MediaDataType.prototype, "size", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
43
|
+
], MediaDataType.prototype, "path", void 0);
|
|
32
44
|
__decorate([
|
|
33
45
|
(0, couchset_1.Field)(() => String, { nullable: true })
|
|
34
46
|
], MediaDataType.prototype, "url", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.model.js","sourceRoot":"","sources":["../../src/media/media.model.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAkD;AAElD,MAAM,SAAS,GAAG,OAAO,CAAC;AAC1B;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;
|
|
1
|
+
{"version":3,"file":"media.model.js","sourceRoot":"","sources":["../../src/media/media.model.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAkD;AAElD,MAAM,SAAS,GAAG,OAAO,CAAC;AAC1B;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;CAuCzB,CAAA;AArCG;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;yCAC1B;AAGZ;IADC,IAAA,gBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,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C,SAAS,CAAC,CAAC;AAE1D,kBAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FileInput, FileStringInput } from './file.input';
|
|
2
|
+
import { MediaDataType } from './media.model';
|
|
3
|
+
export declare class MediaResolverFastdfs {
|
|
4
|
+
uploadFastdfs(files: FileInput[], owner: string): Promise<MediaDataType[]>;
|
|
5
|
+
uploadStringFastdfs(files: FileStringInput[], owner: string): Promise<MediaDataType[]>;
|
|
6
|
+
}
|
|
7
|
+
export default MediaResolverFastdfs;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.MediaResolverFastdfs = void 0;
|
|
27
|
+
const client_graphql_1 = require("@stoqey/client-graphql");
|
|
28
|
+
const util_1 = require("util");
|
|
29
|
+
const stream_1 = require("stream");
|
|
30
|
+
const type_graphql_1 = require("type-graphql");
|
|
31
|
+
const file_input_1 = require("./file.input");
|
|
32
|
+
const media_model_1 = require("./media.model");
|
|
33
|
+
const uuid_1 = require("../_utils/uuid");
|
|
34
|
+
const file_utils_1 = require("../_utils/file.utils");
|
|
35
|
+
const media_methods_1 = require("./media.methods");
|
|
36
|
+
const logs_1 = require("@roadmanjs/logs");
|
|
37
|
+
const fs_1 = __importDefault(require("fs"));
|
|
38
|
+
const GraphQLUpload_js_1 = __importDefault(require("graphql-upload/GraphQLUpload.js"));
|
|
39
|
+
const finishes = (0, util_1.promisify)(stream_1.finished);
|
|
40
|
+
let MediaResolverFastdfs = class MediaResolverFastdfs {
|
|
41
|
+
// for web based Files uploadFileToFastdfs
|
|
42
|
+
async uploadFastdfs(files, owner) {
|
|
43
|
+
const [error, allFiles] = await (0, client_graphql_1.awaitTo)(Promise.all(files.map(async (file) => {
|
|
44
|
+
const _a = await file, { encoding, filename, mimetype } = _a, others = __rest(_a, ["encoding", "filename", "mimetype"]);
|
|
45
|
+
const newFileNameID = (0, uuid_1.generateUUID)();
|
|
46
|
+
const fileExt = (0, file_utils_1.getFileExtension)(mimetype);
|
|
47
|
+
const fullfilename = `${newFileNameID}.${fileExt}`;
|
|
48
|
+
const createReadStream = others.createReadStream;
|
|
49
|
+
(0, logs_1.log)('preview ---------------------------->', {
|
|
50
|
+
filename,
|
|
51
|
+
mimetype,
|
|
52
|
+
encoding,
|
|
53
|
+
fileExt,
|
|
54
|
+
});
|
|
55
|
+
// Save file to local
|
|
56
|
+
const localFile = `/tmp/${fullfilename}`;
|
|
57
|
+
const stream = createReadStream();
|
|
58
|
+
const out = fs_1.default.createWriteStream(localFile);
|
|
59
|
+
stream.pipe(out);
|
|
60
|
+
await finishes(out);
|
|
61
|
+
// Save file to cloud
|
|
62
|
+
const savedToCloudUrl = await (0, media_methods_1.uploadFileToFastdfs)(localFile, fullfilename);
|
|
63
|
+
if (!savedToCloudUrl) {
|
|
64
|
+
throw new Error('Not saved to cloud, please try again');
|
|
65
|
+
}
|
|
66
|
+
// Save file to db
|
|
67
|
+
const newMediaData = {
|
|
68
|
+
id: newFileNameID,
|
|
69
|
+
name: filename,
|
|
70
|
+
filename,
|
|
71
|
+
mimetype,
|
|
72
|
+
encoding,
|
|
73
|
+
owner,
|
|
74
|
+
size: savedToCloudUrl.size,
|
|
75
|
+
path: savedToCloudUrl.path,
|
|
76
|
+
url: savedToCloudUrl.url,
|
|
77
|
+
server: 'fastdfs',
|
|
78
|
+
};
|
|
79
|
+
await media_model_1.MediaDataModel.create(newMediaData);
|
|
80
|
+
// Return file
|
|
81
|
+
return newMediaData;
|
|
82
|
+
})));
|
|
83
|
+
if (allFiles) {
|
|
84
|
+
return allFiles;
|
|
85
|
+
}
|
|
86
|
+
if (error) {
|
|
87
|
+
console.error(error);
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
// For expo strings files in base64
|
|
92
|
+
async uploadStringFastdfs(files, owner) {
|
|
93
|
+
const [error, allFiles] = await (0, client_graphql_1.awaitTo)(Promise.all(files.map(async (file) => {
|
|
94
|
+
const { filename, mimetype, uri } = file;
|
|
95
|
+
const encoding = 'base64';
|
|
96
|
+
let uriData = uri;
|
|
97
|
+
const newFileNameID = (0, uuid_1.generateUUID)();
|
|
98
|
+
const fileExt = (0, file_utils_1.getFileExtension)(mimetype);
|
|
99
|
+
const fullfilename = `${newFileNameID}.${fileExt}`;
|
|
100
|
+
(0, logs_1.log)('preview ---------------------------->', {
|
|
101
|
+
filename,
|
|
102
|
+
mimetype,
|
|
103
|
+
fileExt,
|
|
104
|
+
});
|
|
105
|
+
// remove the the prefixes
|
|
106
|
+
// TODO for audio files, and other files, focus on images for now
|
|
107
|
+
// TODO move to utility
|
|
108
|
+
if (fileExt === 'png') {
|
|
109
|
+
uriData = uriData.replace(/^data:image\/png;base64,/, '');
|
|
110
|
+
}
|
|
111
|
+
if (fileExt === 'jpeg') {
|
|
112
|
+
uriData = uriData.replace(/^data:image\/jpeg;base64,/, '');
|
|
113
|
+
}
|
|
114
|
+
// Save file to local
|
|
115
|
+
const localFile = `/tmp/${fullfilename}`;
|
|
116
|
+
fs_1.default.writeFileSync(localFile, uriData, { encoding });
|
|
117
|
+
// Save file to cloud
|
|
118
|
+
const savedToCloudUrl = await (0, media_methods_1.uploadFileToFastdfs)(localFile, fullfilename);
|
|
119
|
+
if (!savedToCloudUrl) {
|
|
120
|
+
throw new Error('Not saved to cloud, please try again');
|
|
121
|
+
}
|
|
122
|
+
// Save file to db
|
|
123
|
+
const newMediaData = {
|
|
124
|
+
id: newFileNameID,
|
|
125
|
+
name: filename,
|
|
126
|
+
filename,
|
|
127
|
+
mimetype,
|
|
128
|
+
encoding,
|
|
129
|
+
owner,
|
|
130
|
+
size: savedToCloudUrl.size,
|
|
131
|
+
path: savedToCloudUrl.path,
|
|
132
|
+
url: savedToCloudUrl.url,
|
|
133
|
+
server: 'fastdfs',
|
|
134
|
+
};
|
|
135
|
+
await media_model_1.MediaDataModel.create(newMediaData);
|
|
136
|
+
// Return file
|
|
137
|
+
return newMediaData;
|
|
138
|
+
})));
|
|
139
|
+
if (allFiles) {
|
|
140
|
+
return allFiles;
|
|
141
|
+
}
|
|
142
|
+
if (error) {
|
|
143
|
+
console.error(error);
|
|
144
|
+
}
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
__decorate([
|
|
149
|
+
(0, type_graphql_1.Mutation)(() => [media_model_1.MediaDataType]),
|
|
150
|
+
__param(0, (0, type_graphql_1.Arg)('files', () => [GraphQLUpload_js_1.default], { nullable: false })),
|
|
151
|
+
__param(1, (0, type_graphql_1.Arg)('owner', () => String, { nullable: true }))
|
|
152
|
+
], MediaResolverFastdfs.prototype, "uploadFastdfs", null);
|
|
153
|
+
__decorate([
|
|
154
|
+
(0, type_graphql_1.Mutation)(() => [media_model_1.MediaDataType]),
|
|
155
|
+
__param(0, (0, type_graphql_1.Arg)('files', () => [file_input_1.FileStringInput], { nullable: false })),
|
|
156
|
+
__param(1, (0, type_graphql_1.Arg)('owner', () => String, { nullable: true }))
|
|
157
|
+
], MediaResolverFastdfs.prototype, "uploadStringFastdfs", null);
|
|
158
|
+
MediaResolverFastdfs = __decorate([
|
|
159
|
+
(0, type_graphql_1.Resolver)(media_model_1.MediaDataType)
|
|
160
|
+
], MediaResolverFastdfs);
|
|
161
|
+
exports.MediaResolverFastdfs = MediaResolverFastdfs;
|
|
162
|
+
exports.default = MediaResolverFastdfs;
|
|
163
|
+
//# sourceMappingURL=media.resolver.fastdfs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.resolver.fastdfs.js","sourceRoot":"","sources":["../../src/media/media.resolver.fastdfs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA+C;AAC/C,+BAA+B;AAC/B,mCAAgC;AAChC,+CAAqD;AACrD,6CAAwD;AACxD,+CAA4D;AAC5D,yCAA4C;AAC5C,qDAAsD;AACtD,mDAAoD;AACpD,0CAAoC;AACpC,4CAAoB;AACpB,uFAA4D;AAE5D,MAAM,QAAQ,GAAG,IAAA,gBAAS,EAAC,iBAAQ,CAAC,CAAC;AAErC,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAC7B,0CAA0C;IAE1C,KAAK,CAAC,aAAa,CACyC,KAAkB,EAC5B,KAAa;QAE3D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,MAAM,IAAA,w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EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;yDAiEhD;AAID;IADC,IAAA,uBAAQ,EAAC,GAAG,EAAE,CAAC,CAAC,2BAAa,CAAC,CAAC;IAE3B,WAAA,IAAA,kBAAG,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,4BAAe,CAAC,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC,CAAA;IAExD,WAAA,IAAA,kBAAG,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;+DA2EhD;AAxJQ,oBAAoB;IADhC,IAAA,uBAAQ,EAAC,2BAAa,CAAC;GACX,oBAAoB,CAyJhC;AAzJY,oDAAoB;AA2JjC,kBAAe,oBAAoB,CAAC"}
|
package/dist/roadman.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { RoadMan } from '@roadmanjs/core';
|
|
2
2
|
import MediaResolver from './media/media.resolver';
|
|
3
|
+
import MediaResolverFastdfs from './media/media.resolver.fastdfs';
|
|
3
4
|
/**
|
|
4
5
|
* A firebase roadman
|
|
5
6
|
* @param RoadmanBuild
|
|
7
|
+
* TODO mediaRoadman
|
|
6
8
|
*/
|
|
7
9
|
export declare const firebaseRoadman: RoadMan;
|
|
8
|
-
export declare const getMediaFileUploadResolvers: () => (typeof MediaResolver)[];
|
|
10
|
+
export declare const getMediaFileUploadResolvers: () => (typeof MediaResolver | typeof MediaResolverFastdfs)[];
|
package/dist/roadman.js
CHANGED
|
@@ -5,19 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getMediaFileUploadResolvers = exports.firebaseRoadman = void 0;
|
|
7
7
|
const media_resolver_1 = __importDefault(require("./media/media.resolver"));
|
|
8
|
+
const media_resolver_fastdfs_1 = __importDefault(require("./media/media.resolver.fastdfs"));
|
|
8
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
10
|
const firebase_1 = require("./firebase");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
10
12
|
const logs_1 = require("@roadmanjs/logs");
|
|
11
13
|
/**
|
|
12
14
|
* A firebase roadman
|
|
13
15
|
* @param RoadmanBuild
|
|
16
|
+
* TODO mediaRoadman
|
|
14
17
|
*/
|
|
15
18
|
const firebaseRoadman = async (args) => {
|
|
16
19
|
const { projectId } = await (0, firebase_1.configureFirebase)();
|
|
17
20
|
(0, logs_1.log)('ROADMAN: Firebase', chalk_1.default.greenBright('**************************************ProjectID********************', projectId));
|
|
21
|
+
const FASTDFS_SERVER = process.env.FASTDFS_SERVER;
|
|
22
|
+
(0, logs_1.log)('ROADMAN: FASTDFS', (0, lodash_1.isEmpty)(FASTDFS_SERVER)
|
|
23
|
+
? chalk_1.default.redBright('FASTDFS_SERVER not set')
|
|
24
|
+
: chalk_1.default.greenBright('**************************************FASTDFS********************', FASTDFS_SERVER));
|
|
18
25
|
return args;
|
|
19
26
|
};
|
|
20
27
|
exports.firebaseRoadman = firebaseRoadman;
|
|
21
|
-
const getMediaFileUploadResolvers = () => [media_resolver_1.default];
|
|
28
|
+
const getMediaFileUploadResolvers = () => [media_resolver_1.default, media_resolver_fastdfs_1.default];
|
|
22
29
|
exports.getMediaFileUploadResolvers = getMediaFileUploadResolvers;
|
|
23
30
|
//# sourceMappingURL=roadman.js.map
|
package/dist/roadman.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roadman.js","sourceRoot":"","sources":["../src/roadman.ts"],"names":[],"mappings":";;;;;;AAEA,4EAAmD;AACnD,kDAA0B;AAC1B,yCAA6C;AAC7C,0CAAoC;AAEpC
|
|
1
|
+
{"version":3,"file":"roadman.js","sourceRoot":"","sources":["../src/roadman.ts"],"names":[],"mappings":";;;;;;AAEA,4EAAmD;AACnD,4FAAkE;AAClE,kDAA0B;AAC1B,yCAA6C;AAC7C,mCAA+B;AAC/B,0CAAoC;AAEpC;;;;GAIG;AACI,MAAM,eAAe,GAAY,KAAK,EAAE,IAAkB,EAAyB,EAAE;IACxF,MAAM,EAAC,SAAS,EAAC,GAAG,MAAM,IAAA,4BAAiB,GAAE,CAAC;IAE9C,IAAA,UAAG,EACC,mBAAmB,EACnB,eAAK,CAAC,WAAW,CACb,qEAAqE,EACrE,SAAS,CACZ,CACJ,CAAC;IAEF,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAElD,IAAA,UAAG,EACC,kBAAkB,EAClB,IAAA,gBAAO,EAAC,cAAc,CAAC;QACnB,CAAC,CAAC,eAAK,CAAC,SAAS,CAAC,wBAAwB,CAAC;QAC3C,CAAC,CAAC,eAAK,CAAC,WAAW,CACb,mEAAmE,EACnE,cAAc,CACjB,CACV,CAAC;IAEF,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAxBW,QAAA,eAAe,mBAwB1B;AAEK,MAAM,2BAA2B,GAAG,GAAG,EAAE,CAAC,CAAC,wBAAa,EAAE,gCAAoB,CAAC,CAAC;AAA1E,QAAA,2BAA2B,+BAA+C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roadmanjs/firebase-admin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "A roadman for firebase-admin",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"@types/lodash": "^4.14.168",
|
|
44
44
|
"@types/mocha": "^8.2.0",
|
|
45
45
|
"@types/node": "^10.0.3",
|
|
46
|
+
"@types/request": "^2.48.8",
|
|
46
47
|
"@types/source-map-support": "^0.4.0",
|
|
47
48
|
"@types/uuid": "8.3.1",
|
|
48
49
|
"@typescript-eslint/eslint-plugin": "^3.4.0",
|
|
@@ -84,6 +85,7 @@
|
|
|
84
85
|
"firebase-admin": "^10.0.0",
|
|
85
86
|
"graphql-upload": "15.0.2",
|
|
86
87
|
"lodash": "^4.17.20",
|
|
88
|
+
"request": "^2.88.2",
|
|
87
89
|
"uuid": "^8.3.2"
|
|
88
90
|
}
|
|
89
91
|
}
|