@roadmanjs/firebase-admin 1.2.1 → 1.3.0
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/media/media.methods.d.ts +2 -0
- package/dist/media/media.methods.d.ts.map +1 -0
- package/dist/media/media.methods.js +36 -0
- package/dist/media/media.methods.js.map +1 -0
- package/dist/media/media.model.d.ts +2 -0
- package/dist/media/media.model.d.ts.map +1 -1
- package/dist/media/media.model.js +4 -3
- package/dist/media/media.model.js.map +1 -1
- package/dist/media/media.resolver.d.ts +9 -0
- package/dist/media/media.resolver.d.ts.map +1 -0
- package/dist/media/media.resolver.js +164 -0
- package/dist/media/media.resolver.js.map +1 -0
- package/dist/middlewares/isAuth.d.ts +12 -0
- package/dist/middlewares/isAuth.d.ts.map +1 -0
- package/dist/middlewares/isAuth.js +36 -0
- package/dist/middlewares/isAuth.js.map +1 -0
- package/dist/roadman.d.ts +2 -0
- package/dist/roadman.d.ts.map +1 -1
- package/dist/roadman.js +7 -3
- package/dist/roadman.js.map +1 -1
- package/dist/shared.d.ts +9 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +3 -0
- package/dist/shared.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.methods.d.ts","sourceRoot":"","sources":["../../src/media/media.methods.ts"],"names":[],"mappings":"AAEA,wBAAsB,kBAAkB,CACpC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,WAAW,SAAc,GAC1B,OAAO,CAAC,MAAM,CAAC,CAgCjB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadFileToBucket = uploadFileToBucket;
|
|
4
|
+
const firebase_1 = require("../firebase");
|
|
5
|
+
const logs_1 = require("@roadmanjs/logs");
|
|
6
|
+
async function uploadFileToBucket(filePath, fileDest, contentType = 'image/png') {
|
|
7
|
+
const { projectId, storage: adminStorage } = await (0, firebase_1.configureFirebase)();
|
|
8
|
+
const storage = adminStorage();
|
|
9
|
+
const bucketName = `${projectId}.appspot.com`;
|
|
10
|
+
// const DefaultPlaceholder = `https://storage.googleapis.com/${bucketName}/placeholder.png`;
|
|
11
|
+
// Uploads a local file to the bucket
|
|
12
|
+
try {
|
|
13
|
+
const bucket = storage.bucket(bucketName);
|
|
14
|
+
await bucket.upload(filePath, {
|
|
15
|
+
public: true,
|
|
16
|
+
destination: fileDest,
|
|
17
|
+
// By setting the option `destination`, you can change the name of the
|
|
18
|
+
// object you are uploading to a bucket.
|
|
19
|
+
metadata: {
|
|
20
|
+
contentType,
|
|
21
|
+
// Enable long-lived HTTP caching headers
|
|
22
|
+
// Use only if the contents of the file will never change
|
|
23
|
+
cacheControl: 'no-cache',
|
|
24
|
+
// cacheControl: 'public, max-age=31536000',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const publicUrl = `https://storage.googleapis.com/${bucketName}/${fileDest}`;
|
|
28
|
+
(0, logs_1.log)(`Public url -> ${publicUrl}`);
|
|
29
|
+
return publicUrl;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
(0, logs_1.log)('error uploading file', JSON.stringify(error));
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=media.methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.methods.js","sourceRoot":"","sources":["../../src/media/media.methods.ts"],"names":[],"mappings":";;AAEA,gDAoCC;AAtCD,0CAA8C;AAC9C,0CAAoC;AAC7B,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,CAAC;QACD,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,SAAS,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAA,UAAG,EAAC,sBAAsB,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACnD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Model } from 'couchset';
|
|
1
2
|
/**
|
|
2
3
|
* GraphQL Types start
|
|
3
4
|
*/
|
|
@@ -18,5 +19,6 @@ export declare class MediaDataType {
|
|
|
18
19
|
/**
|
|
19
20
|
* GraphQL Types end
|
|
20
21
|
*/
|
|
22
|
+
export declare const MediaDataModel: Model;
|
|
21
23
|
export default MediaDataType;
|
|
22
24
|
//# sourceMappingURL=media.model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.model.d.ts","sourceRoot":"","sources":["../../src/media/media.model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"media.model.d.ts","sourceRoot":"","sources":["../../src/media/media.model.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAG/B;;GAEG;AACH,qBACa,aAAa;IAEtB,EAAE,CAAC,EAAE,MAAM,CAAC;IAGZ,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAMlB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,GAAG,CAAC,EAAE,MAAM,CAAC;IAGb,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,SAAS,CAAC,EAAE,IAAI,CAAC;IAGjB,SAAS,CAAC,EAAE,IAAI,CAAC;CACpB;AAED;;GAEG;AAEH,eAAO,MAAM,cAAc,EAAE,KAA4B,CAAC;AAE1D,eAAe,aAAa,CAAC"}
|
|
@@ -6,9 +6,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.MediaDataType = void 0;
|
|
9
|
+
exports.MediaDataModel = exports.MediaDataType = void 0;
|
|
10
10
|
const type_graphql_1 = require("type-graphql");
|
|
11
|
-
|
|
11
|
+
const couchset_1 = require("couchset");
|
|
12
|
+
const modelName = 'media';
|
|
12
13
|
/**
|
|
13
14
|
* GraphQL Types start
|
|
14
15
|
*/
|
|
@@ -60,6 +61,6 @@ exports.MediaDataType = MediaDataType = __decorate([
|
|
|
60
61
|
/**
|
|
61
62
|
* GraphQL Types end
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
+
exports.MediaDataModel = new couchset_1.Model(modelName);
|
|
64
65
|
exports.default = MediaDataType;
|
|
65
66
|
//# sourceMappingURL=media.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.model.js","sourceRoot":"","sources":["../../src/media/media.model.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+CAA+C;
|
|
1
|
+
{"version":3,"file":"media.model.js","sourceRoot":"","sources":["../../src/media/media.model.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+CAA+C;AAC/C,uCAA+B;AAE/B,MAAM,SAAS,GAAG,OAAO,CAAC;AAC1B;;GAEG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;CAuCzB,CAAA;AAvCY,sCAAa;AAEtB;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;yCAC1B;AAGZ;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;2CACxB;AAGd;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;+CACpB;AAGlB;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;+CACpB;AAGlB;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;+CACpB;AAMlB;IAJC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE;QACjB,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,kDAAkD;KAClE,CAAC;6CACc;AAGhB;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;2CACxB;AAGd;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;2CACxB;AAGd;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;0CACzB;AAGb;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;4CACvB;AAGf;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;gDACnB;AAGjB;IADC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;gDACnB;wBAtCR,aAAa;IADzB,IAAA,yBAAU,GAAE;GACA,aAAa,CAuCzB;AAED;;GAEG;AAEU,QAAA,cAAc,GAAU,IAAI,gBAAK,CAAC,SAAS,CAAC,CAAC;AAE1D,kBAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FileInput, FileStringInput } from './file.input';
|
|
2
|
+
import { MediaDataType } from './media.model';
|
|
3
|
+
import { ContextType } from '../shared';
|
|
4
|
+
export declare class MediaResolver {
|
|
5
|
+
upload(ctx: ContextType, files: FileInput[]): Promise<MediaDataType[]>;
|
|
6
|
+
uploadString(ctx: ContextType, files: FileStringInput[]): Promise<MediaDataType[]>;
|
|
7
|
+
}
|
|
8
|
+
export default MediaResolver;
|
|
9
|
+
//# sourceMappingURL=media.resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.resolver.d.ts","sourceRoot":"","sources":["../../src/media/media.resolver.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AACxD,OAAO,EAAiB,aAAa,EAAC,MAAM,eAAe,CAAC;AAQ5D,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAKtC,qBACa,aAAa;IAIhB,MAAM,CACD,GAAG,EAAE,WAAW,EACiC,KAAK,EAAE,SAAS,EAAE,GAC3E,OAAO,CAAC,aAAa,EAAE,CAAC;IAuErB,YAAY,CACP,GAAG,EAAE,WAAW,EAEvB,KAAK,EAAE,eAAe,EAAE,GACzB,OAAO,CAAC,aAAa,EAAE,CAAC;CA6E9B;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
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.MediaResolver = 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 get_1 = __importDefault(require("lodash/get"));
|
|
39
|
+
const isAuth_1 = require("../middlewares/isAuth");
|
|
40
|
+
// TODO
|
|
41
|
+
const graphql_upload_1 = require("graphql-upload");
|
|
42
|
+
const finishes = (0, util_1.promisify)(stream_1.finished);
|
|
43
|
+
let MediaResolver = class MediaResolver {
|
|
44
|
+
// for web based Files
|
|
45
|
+
async upload(ctx, files) {
|
|
46
|
+
const owner = (0, get_1.default)(ctx, 'payload.userId', '');
|
|
47
|
+
const [error, allFiles] = await (0, client_graphql_1.awaitTo)(Promise.all(files.map(async (file) => {
|
|
48
|
+
const _a = await file, { encoding, filename, mimetype } = _a, others = __rest(_a, ["encoding", "filename", "mimetype"]);
|
|
49
|
+
const newFileNameID = (0, uuid_1.generateUUID)();
|
|
50
|
+
const fileExt = (0, file_utils_1.getFileExtension)(mimetype);
|
|
51
|
+
const fullfilename = `${newFileNameID}.${fileExt}`;
|
|
52
|
+
const createReadStream = others.createReadStream;
|
|
53
|
+
(0, logs_1.log)('preview ---------------------------->', {
|
|
54
|
+
filename,
|
|
55
|
+
mimetype,
|
|
56
|
+
encoding,
|
|
57
|
+
fileExt,
|
|
58
|
+
});
|
|
59
|
+
// Save file to local
|
|
60
|
+
const localFile = `/tmp/${fullfilename}`;
|
|
61
|
+
const stream = createReadStream();
|
|
62
|
+
const out = fs_1.default.createWriteStream(localFile);
|
|
63
|
+
stream.pipe(out);
|
|
64
|
+
await finishes(out);
|
|
65
|
+
// Save file to cloud
|
|
66
|
+
const savedToCloudUrl = await (0, media_methods_1.uploadFileToBucket)(localFile, fullfilename, mimetype);
|
|
67
|
+
if (!savedToCloudUrl) {
|
|
68
|
+
throw new Error('Not saved to cloud, please try again');
|
|
69
|
+
}
|
|
70
|
+
// Save file to db
|
|
71
|
+
const newMediaData = {
|
|
72
|
+
id: newFileNameID,
|
|
73
|
+
name: filename,
|
|
74
|
+
filename,
|
|
75
|
+
mimetype,
|
|
76
|
+
encoding,
|
|
77
|
+
owner,
|
|
78
|
+
url: savedToCloudUrl,
|
|
79
|
+
};
|
|
80
|
+
await media_model_1.MediaDataModel.create(newMediaData);
|
|
81
|
+
// Return file
|
|
82
|
+
return newMediaData;
|
|
83
|
+
})));
|
|
84
|
+
if (allFiles) {
|
|
85
|
+
return allFiles;
|
|
86
|
+
}
|
|
87
|
+
if (error) {
|
|
88
|
+
console.error(error);
|
|
89
|
+
}
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
// For expo strings files in base64
|
|
93
|
+
async uploadString(ctx, files) {
|
|
94
|
+
const owner = (0, get_1.default)(ctx, 'payload.userId', '');
|
|
95
|
+
const [error, allFiles] = await (0, client_graphql_1.awaitTo)(Promise.all(files.map(async (file) => {
|
|
96
|
+
const { filename, mimetype, uri } = file;
|
|
97
|
+
const encoding = 'base64';
|
|
98
|
+
let uriData = uri;
|
|
99
|
+
const newFileNameID = (0, uuid_1.generateUUID)();
|
|
100
|
+
const fileExt = (0, file_utils_1.getFileExtension)(mimetype);
|
|
101
|
+
const fullfilename = `${newFileNameID}.${fileExt}`;
|
|
102
|
+
(0, logs_1.log)('preview ---------------------------->', {
|
|
103
|
+
filename,
|
|
104
|
+
mimetype,
|
|
105
|
+
fileExt,
|
|
106
|
+
});
|
|
107
|
+
// remove the the prefixes
|
|
108
|
+
// TODO for audio files, and other files, focus on images for now
|
|
109
|
+
// TODO move to utility
|
|
110
|
+
if (fileExt === 'png') {
|
|
111
|
+
uriData = uriData.replace(/^data:image\/png;base64,/, '');
|
|
112
|
+
}
|
|
113
|
+
if (fileExt === 'jpeg') {
|
|
114
|
+
uriData = uriData.replace(/^data:image\/jpeg;base64,/, '');
|
|
115
|
+
}
|
|
116
|
+
// Save file to local
|
|
117
|
+
const localFile = `/tmp/${fullfilename}`;
|
|
118
|
+
fs_1.default.writeFileSync(localFile, uriData, { encoding });
|
|
119
|
+
// Save file to cloud
|
|
120
|
+
const savedToCloudUrl = await (0, media_methods_1.uploadFileToBucket)(localFile, fullfilename, mimetype);
|
|
121
|
+
if (!savedToCloudUrl) {
|
|
122
|
+
throw new Error('Not saved to cloud, please try again');
|
|
123
|
+
}
|
|
124
|
+
// Save file to db
|
|
125
|
+
const newMediaData = {
|
|
126
|
+
id: newFileNameID,
|
|
127
|
+
name: filename,
|
|
128
|
+
filename,
|
|
129
|
+
mimetype,
|
|
130
|
+
encoding,
|
|
131
|
+
owner,
|
|
132
|
+
url: savedToCloudUrl,
|
|
133
|
+
};
|
|
134
|
+
await media_model_1.MediaDataModel.create(newMediaData);
|
|
135
|
+
// Return file
|
|
136
|
+
return newMediaData;
|
|
137
|
+
})));
|
|
138
|
+
if (allFiles) {
|
|
139
|
+
return allFiles;
|
|
140
|
+
}
|
|
141
|
+
if (error) {
|
|
142
|
+
console.error(error);
|
|
143
|
+
}
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
exports.MediaResolver = MediaResolver;
|
|
148
|
+
__decorate([
|
|
149
|
+
(0, type_graphql_1.UseMiddleware)(isAuth_1.isAuth),
|
|
150
|
+
(0, type_graphql_1.Mutation)(() => [media_model_1.MediaDataType]),
|
|
151
|
+
__param(0, (0, type_graphql_1.Ctx)()),
|
|
152
|
+
__param(1, (0, type_graphql_1.Arg)('files', () => [graphql_upload_1.GraphQLUpload], { nullable: false }))
|
|
153
|
+
], MediaResolver.prototype, "upload", null);
|
|
154
|
+
__decorate([
|
|
155
|
+
(0, type_graphql_1.UseMiddleware)(isAuth_1.isAuth),
|
|
156
|
+
(0, type_graphql_1.Mutation)(() => [media_model_1.MediaDataType]),
|
|
157
|
+
__param(0, (0, type_graphql_1.Ctx)()),
|
|
158
|
+
__param(1, (0, type_graphql_1.Arg)('files', () => [file_input_1.FileStringInput], { nullable: false }))
|
|
159
|
+
], MediaResolver.prototype, "uploadString", null);
|
|
160
|
+
exports.MediaResolver = MediaResolver = __decorate([
|
|
161
|
+
(0, type_graphql_1.Resolver)(media_model_1.MediaDataType)
|
|
162
|
+
], MediaResolver);
|
|
163
|
+
exports.default = MediaResolver;
|
|
164
|
+
//# sourceMappingURL=media.resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.resolver.js","sourceRoot":"","sources":["../../src/media/media.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA+C;AAC/C,+BAA+B;AAC/B,mCAAgC;AAChC,+CAAyE;AACzE,6CAAwD;AACxD,+CAA4D;AAC5D,yCAA4C;AAC5C,qDAAsD;AACtD,mDAAmD;AACnD,0CAAoC;AACpC,4CAAoB;AACpB,qDAA8B;AAC9B,kDAA6C;AAG7C,OAAO;AACP,mDAA6C;AAC7C,MAAM,QAAQ,GAAG,IAAA,gBAAS,EAAC,iBAAQ,CAAC,CAAC;AAE9B,IAAM,aAAa,GAAnB,MAAM,aAAa;IACtB,sBAAsB;IAGhB,AAAN,KAAK,CAAC,MAAM,CACD,GAAgB,EACiC,KAAkB;QAE1E,MAAM,KAAK,GAAG,IAAA,aAAI,EAAC,GAAG,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAAC;QAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,MAAM,IAAA,wBAAO,EACnC,O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EAAC,CAAC,CAAA;2CAmE1D;AAKK;IAFL,IAAA,4BAAa,EAAC,eAAM,CAAC;IACrB,IAAA,uBAAQ,EAAC,GAAG,EAAE,CAAC,CAAC,2BAAa,CAAC,CAAC;IAE3B,WAAA,IAAA,kBAAG,GAAE,CAAA;IACL,WAAA,IAAA,kBAAG,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,4BAAe,CAAC,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC,CAAA;iDA8E5D;wBA9JQ,aAAa;IADzB,IAAA,uBAAQ,EAAC,2BAAa,CAAC;GACX,aAAa,CA+JzB;AAED,kBAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContextType } from '../shared';
|
|
2
|
+
import { MiddlewareFn } from 'type-graphql';
|
|
3
|
+
import { JwtPayload } from 'jsonwebtoken';
|
|
4
|
+
export declare const verifyAuthToken: (token: string) => string | JwtPayload;
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @sets context.payload = { userId, iat, exp }
|
|
8
|
+
* @param next
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare const isAuth: MiddlewareFn<ContextType>;
|
|
12
|
+
//# sourceMappingURL=isAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAuth.d.ts","sourceRoot":"","sources":["../../src/middlewares/isAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAC,UAAU,EAAS,MAAM,cAAc,CAAC;AAEhD,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,MAAM,GAAG,UAIxD,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,MAAM,EAAE,YAAY,CAAC,WAAW,CAiB5C,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAuth = exports.verifyAuthToken = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const logs_1 = require("@roadmanjs/logs");
|
|
6
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
7
|
+
const verifyAuthToken = (token) => {
|
|
8
|
+
const secret = (0, lodash_1.get)(process.env, 'ACCESS_TOKEN_SECRET', '');
|
|
9
|
+
const verified = (0, jsonwebtoken_1.verify)(token, secret, { ignoreExpiration: false });
|
|
10
|
+
return verified;
|
|
11
|
+
};
|
|
12
|
+
exports.verifyAuthToken = verifyAuthToken;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @sets context.payload = { userId, iat, exp }
|
|
16
|
+
* @param next
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
const isAuth = ({ context }, next) => {
|
|
20
|
+
const authorization = (0, lodash_1.get)(context, 'req.headers.authorization', '');
|
|
21
|
+
if ((0, lodash_1.isEmpty)(authorization)) {
|
|
22
|
+
throw new Error('Not Authenticated');
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const token = authorization.split(' ')[1];
|
|
26
|
+
const verified = (0, exports.verifyAuthToken)(token);
|
|
27
|
+
context.payload = verified;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
(0, logs_1.log)('not authenticated');
|
|
31
|
+
throw new Error('not authenticated');
|
|
32
|
+
}
|
|
33
|
+
return next();
|
|
34
|
+
};
|
|
35
|
+
exports.isAuth = isAuth;
|
|
36
|
+
//# sourceMappingURL=isAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAuth.js","sourceRoot":"","sources":["../../src/middlewares/isAuth.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAI5C,0CAAoC;AACpC,+CAAgD;AAEzC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAuB,EAAE;IAClE,MAAM,MAAM,GAAG,IAAA,YAAI,EAAC,OAAO,CAAC,GAAG,EAAE,qBAAqB,EAAE,EAAE,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,IAAA,qBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,EAAC,gBAAgB,EAAE,KAAK,EAAC,CAAC,CAAC;IAClE,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B;AACF;;;;;GAKG;AACI,MAAM,MAAM,GAA8B,CAAC,EAAC,OAAO,EAAC,EAAE,IAAI,EAAE,EAAE;IACjE,MAAM,aAAa,GAAG,IAAA,YAAI,EAAC,OAAO,EAAE,2BAA2B,EAAE,EAAE,CAAC,CAAC;IAErE,IAAI,IAAA,gBAAO,EAAC,aAAa,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC;QACD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAC;QACxC,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,IAAA,UAAG,EAAC,mBAAmB,CAAC,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,IAAI,EAAE,CAAC;AAClB,CAAC,CAAC;AAjBW,QAAA,MAAM,UAiBjB"}
|
package/dist/roadman.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { RoadMan } from '@roadmanjs/core';
|
|
2
|
+
import MediaResolver from './media/media.resolver';
|
|
2
3
|
/**
|
|
3
4
|
* A firebase roadman
|
|
4
5
|
* @param RoadmanBuild
|
|
5
6
|
* TODO mediaRoadman
|
|
6
7
|
*/
|
|
7
8
|
export declare const firebaseRoadman: RoadMan;
|
|
9
|
+
export declare const getMediaFileUploadResolvers: () => (typeof MediaResolver)[];
|
|
8
10
|
//# sourceMappingURL=roadman.d.ts.map
|
package/dist/roadman.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roadman.d.ts","sourceRoot":"","sources":["../src/roadman.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAe,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"roadman.d.ts","sourceRoot":"","sources":["../src/roadman.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAe,MAAM,iBAAiB,CAAC;AAE3D,OAAO,aAAa,MAAM,wBAAwB,CAAC;AAMnD;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,OAU7B,CAAC;AAEF,eAAO,MAAM,2BAA2B,gCAAwB,CAAC"}
|
package/dist/roadman.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
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.firebaseRoadman = void 0;
|
|
4
|
-
|
|
6
|
+
exports.getMediaFileUploadResolvers = exports.firebaseRoadman = void 0;
|
|
7
|
+
const media_resolver_1 = __importDefault(require("./media/media.resolver"));
|
|
5
8
|
// import MediaResolverFastdfs from './media/media.resolver.fastdfs';
|
|
6
9
|
const firebase_1 = require("./firebase");
|
|
7
10
|
// import {isEmpty} from 'lodash';
|
|
@@ -17,5 +20,6 @@ const firebaseRoadman = async (args) => {
|
|
|
17
20
|
return args;
|
|
18
21
|
};
|
|
19
22
|
exports.firebaseRoadman = firebaseRoadman;
|
|
20
|
-
|
|
23
|
+
const getMediaFileUploadResolvers = () => [media_resolver_1.default];
|
|
24
|
+
exports.getMediaFileUploadResolvers = getMediaFileUploadResolvers;
|
|
21
25
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"roadman.js","sourceRoot":"","sources":["../src/roadman.ts"],"names":[],"mappings":";;;;;;AAEA,4EAAmD;AACnD,qEAAqE;AACrE,yCAA6C;AAC7C,kCAAkC;AAClC,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,qEAAqE,EACrE,SAAS,CACZ,CAAC;IAEF,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B;AAEK,MAAM,2BAA2B,GAAG,GAAG,EAAE,CAAC,CAAC,wBAAa,CAAC,CAAC;AAApD,QAAA,2BAA2B,+BAAyB"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAE1C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AAE7D,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;IACd,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED