@pittica/drive-folder-qrcode 1.5.1 → 2.1.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.
@@ -1,347 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.uploadFile = exports.paginator = exports.list = exports.hasFile = exports.filename = exports.createFile = void 0;
8
- var _client = _interopRequireDefault(require("./client"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof Symbol ? Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return Object.defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = Object.getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l); function g(t) { ["next", "throw", "return"].forEach(function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
11
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
12
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } // Copyright 2024-2025 Pittica S.r.l.
13
- //
14
- // Licensed under the Apache License, Version 2.0 (the "License");
15
- // you may not use this file except in compliance with the License.
16
- // You may obtain a copy of the License at
17
- //
18
- // http://www.apache.org/licenses/LICENSE-2.0
19
- //
20
- // Unless required by applicable law or agreed to in writing, software
21
- // distributed under the License is distributed on an "AS IS" BASIS,
22
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- // See the License for the specific language governing permissions and
24
- // limitations under the License.
25
- /**
26
- * Lists all subfolders in the folder with the given ID.
27
- *
28
- * @param {string} id Folder ID.
29
- * @param {string} credentials Service account JSON file path.
30
- * @returns {Array} All subfolders in the folder with the given ID.
31
- */
32
- var list = exports.list = /*#__PURE__*/function () {
33
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
34
- var credentials,
35
- files,
36
- token,
37
- results,
38
- _args = arguments;
39
- return _regeneratorRuntime().wrap(function _callee$(_context) {
40
- while (1) switch (_context.prev = _context.next) {
41
- case 0:
42
- credentials = _args.length > 1 && _args[1] !== undefined ? _args[1] : null;
43
- files = [];
44
- token = null;
45
- case 3:
46
- if (!true) {
47
- _context.next = 19;
48
- break;
49
- }
50
- _context.next = 6;
51
- return paginator(id, token, credentials);
52
- case 6:
53
- results = _context.sent;
54
- if (!results) {
55
- _context.next = 16;
56
- break;
57
- }
58
- results.files.forEach(function (file) {
59
- return files.push(file);
60
- });
61
- if (results.nextPageToken) {
62
- _context.next = 13;
63
- break;
64
- }
65
- return _context.abrupt("break", 19);
66
- case 13:
67
- token = results.nextPageToken;
68
- case 14:
69
- _context.next = 17;
70
- break;
71
- case 16:
72
- return _context.abrupt("break", 19);
73
- case 17:
74
- _context.next = 3;
75
- break;
76
- case 19:
77
- return _context.abrupt("return", files);
78
- case 20:
79
- case "end":
80
- return _context.stop();
81
- }
82
- }, _callee);
83
- }));
84
- return function list(_x) {
85
- return _ref.apply(this, arguments);
86
- };
87
- }();
88
-
89
- /**
90
- * Lists all subfolders in the folder with the given ID by page.
91
- *
92
- * @param {string} id Folder ID.
93
- * @param {string} pageToken Page token.
94
- * @param {string} credentials Service account JSON file path.
95
- * @returns {Array} All subfolders in the folder with the given ID.
96
- */
97
- var paginator = exports.paginator = /*#__PURE__*/function () {
98
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id) {
99
- var pageToken,
100
- credentials,
101
- _args2 = arguments;
102
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
103
- while (1) switch (_context2.prev = _context2.next) {
104
- case 0:
105
- pageToken = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : null;
106
- credentials = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : null;
107
- _context2.next = 4;
108
- return (0, _client["default"])(credentials).files.list({
109
- q: "'".concat(id, "' in parents AND mimeType = 'application/vnd.google-apps.folder' AND trashed = false"),
110
- pageToken: pageToken,
111
- pageSize: 15,
112
- spaces: "drive",
113
- fields: "nextPageToken, files(id, name, webViewLink)",
114
- includeItemsFromAllDrives: true,
115
- supportsAllDrives: true
116
- }).then(function (_ref3) {
117
- var data = _ref3.data;
118
- return data;
119
- })["catch"](function (_ref4) {
120
- var code = _ref4.code,
121
- errors = _ref4.errors;
122
- if (errors) {
123
- errors.forEach(function (_ref5) {
124
- var message = _ref5.message;
125
- return console.error(code, message);
126
- });
127
- } else {
128
- console.error(code);
129
- }
130
- return null;
131
- });
132
- case 4:
133
- return _context2.abrupt("return", _context2.sent);
134
- case 5:
135
- case "end":
136
- return _context2.stop();
137
- }
138
- }, _callee2);
139
- }));
140
- return function paginator(_x2) {
141
- return _ref2.apply(this, arguments);
142
- };
143
- }();
144
-
145
- /**
146
- * Creates a file in the given Drive folder.
147
- *
148
- * @param {Drive} client Google Drive client instance.
149
- * @param {string} folder Folder ID.
150
- * @param {string} content File content.
151
- * @param {string} name File name.
152
- * @param {string} mimeType MIME type in "type/sub" format.
153
- * @param {string} credentials Service account JSON file path.
154
- * @returns {File} The created file.
155
- */
156
- var createFile = exports.createFile = /*#__PURE__*/function () {
157
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(client, folder, content, name, mimeType) {
158
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
159
- while (1) switch (_context3.prev = _context3.next) {
160
- case 0:
161
- _context3.next = 2;
162
- return client.files.create({
163
- requestBody: {
164
- name: name,
165
- parents: [folder]
166
- },
167
- media: {
168
- mimeType: mimeType,
169
- body: content
170
- },
171
- fields: ["id", "name"],
172
- uploadType: "multipart",
173
- supportsAllDrives: true
174
- }).then(function (_ref7) {
175
- var data = _ref7.data,
176
- status = _ref7.status;
177
- if (status >= 200 && status < 300) {
178
- console.info("QR code for \"".concat(folder, "\", \"").concat(data.id, "\", created."));
179
- } else {
180
- console.error("Errore creating QR code for \"".concat(folder, "\"."));
181
- }
182
- return data;
183
- })["catch"](function () {
184
- return console.error("Errore creating QR code for \"".concat(folder, "\"."));
185
- });
186
- case 2:
187
- return _context3.abrupt("return", _context3.sent);
188
- case 3:
189
- case "end":
190
- return _context3.stop();
191
- }
192
- }, _callee3);
193
- }));
194
- return function createFile(_x3, _x4, _x5, _x6, _x7) {
195
- return _ref6.apply(this, arguments);
196
- };
197
- }();
198
-
199
- /**
200
- * Creates a file in the given Drive folder, whether it doesn't exist.
201
- *
202
- * @param {string} folder Folder ID.
203
- * @param {string} content File content.
204
- * @param {string} name File name.
205
- * @param {string} mimeType MIME type in "type/sub" format.
206
- * @param {string} credentials Service account JSON file path.
207
- * @returns {File} The created file.
208
- */
209
- var uploadFile = exports.uploadFile = /*#__PURE__*/function () {
210
- var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(folder, content, name, mimeType, credentials) {
211
- var client;
212
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
213
- while (1) switch (_context6.prev = _context6.next) {
214
- case 0:
215
- _context6.next = 2;
216
- return (0, _client["default"])(credentials);
217
- case 2:
218
- client = _context6.sent;
219
- _context6.next = 5;
220
- return client.files.list({
221
- q: "'".concat(folder, "' in parents AND mimeType = '").concat(mimeType, "' AND name = '").concat(name, "' AND trashed = false"),
222
- pageSize: 1,
223
- fields: "files(id, name, trashed, webViewLink)",
224
- spaces: "drive",
225
- includeItemsFromAllDrives: true,
226
- supportsAllDrives: true
227
- }).then(/*#__PURE__*/function () {
228
- var _ref0 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref9) {
229
- var files;
230
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
231
- while (1) switch (_context4.prev = _context4.next) {
232
- case 0:
233
- files = _ref9.data.files;
234
- if (!(files.length > 0)) {
235
- _context4.next = 8;
236
- break;
237
- }
238
- console.info("QR code for \"".concat(folder, "\", \"").concat(files[0].name, "\", already exists."), files[0].webViewLink);
239
- _context4.next = 5;
240
- return client.files.get({
241
- fileId: files[0].id,
242
- alt: "media",
243
- supportsAllDrives: true
244
- });
245
- case 5:
246
- return _context4.abrupt("return", _context4.sent);
247
- case 8:
248
- _context4.next = 10;
249
- return createFile(client, folder, content, name, mimeType);
250
- case 10:
251
- return _context4.abrupt("return", _context4.sent);
252
- case 11:
253
- case "end":
254
- return _context4.stop();
255
- }
256
- }, _callee4);
257
- }));
258
- return function (_x11) {
259
- return _ref0.apply(this, arguments);
260
- };
261
- }())["catch"](/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
262
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
263
- while (1) switch (_context5.prev = _context5.next) {
264
- case 0:
265
- _context5.next = 2;
266
- return createFile(client, folder, content, name, mimeType);
267
- case 2:
268
- return _context5.abrupt("return", _context5.sent);
269
- case 3:
270
- case "end":
271
- return _context5.stop();
272
- }
273
- }, _callee5);
274
- })));
275
- case 5:
276
- return _context6.abrupt("return", _context6.sent);
277
- case 6:
278
- case "end":
279
- return _context6.stop();
280
- }
281
- }, _callee6);
282
- }));
283
- return function uploadFile(_x8, _x9, _x0, _x1, _x10) {
284
- return _ref8.apply(this, arguments);
285
- };
286
- }();
287
-
288
- /**
289
- * Gets an output filename.
290
- *
291
- * @param {object} folder Google Drive folder object.
292
- * @param {string} extension File extension.
293
- * @returns {string} Output filename.
294
- */
295
- var filename = exports.filename = function filename(_ref10, extension) {
296
- var name = _ref10.name,
297
- id = _ref10.id;
298
- return "".concat(name, " - ").concat(id, ".").concat(extension.toLowerCase());
299
- };
300
-
301
- /**
302
- * Determines whether the given file name exists in the given folder.
303
- *
304
- * @param {string} folder Folder ID.
305
- * @param {string} name File name.
306
- * @param {string} credentials Service account JSON file path.
307
- * @returns {boolean} A value indicating whether the given file name exists in the given folder.
308
- */
309
- var hasFile = exports.hasFile = /*#__PURE__*/function () {
310
- var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(folder, name) {
311
- var credentials,
312
- client,
313
- _args7 = arguments;
314
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
315
- while (1) switch (_context7.prev = _context7.next) {
316
- case 0:
317
- credentials = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : null;
318
- _context7.next = 3;
319
- return (0, _client["default"])(credentials);
320
- case 3:
321
- client = _context7.sent;
322
- _context7.next = 6;
323
- return client.files.list({
324
- q: "'".concat(folder, "' in parents AND name = '").concat(name, "' AND trashed = false"),
325
- pageSize: 1,
326
- fields: "files(id)",
327
- spaces: "drive",
328
- includeItemsFromAllDrives: true,
329
- supportsAllDrives: true
330
- }).then(function (_ref12) {
331
- var files = _ref12.data.files;
332
- return files.length > 0;
333
- })["catch"](function () {
334
- return false;
335
- });
336
- case 6:
337
- return _context7.abrupt("return", _context7.sent);
338
- case 7:
339
- case "end":
340
- return _context7.stop();
341
- }
342
- }, _callee7);
343
- }));
344
- return function hasFile(_x12, _x13) {
345
- return _ref11.apply(this, arguments);
346
- };
347
- }();
@@ -1,172 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.process = exports.exists = exports["default"] = void 0;
8
- var _folder = require("../drive/folder");
9
- var _image = _interopRequireDefault(require("../qrcode/image"));
10
- var _logo = require("../qrcode/logo");
11
- var _path = require("path");
12
- var _fs = require("fs");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof Symbol ? Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return Object.defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = Object.getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l); function g(t) { ["next", "throw", "return"].forEach(function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
15
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
16
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } // Copyright 2024-2025 Pittica S.r.l.
17
- //
18
- // Licensed under the Apache License, Version 2.0 (the "License");
19
- // you may not use this file except in compliance with the License.
20
- // You may obtain a copy of the License at
21
- //
22
- // http://www.apache.org/licenses/LICENSE-2.0
23
- //
24
- // Unless required by applicable law or agreed to in writing, software
25
- // distributed under the License is distributed on an "AS IS" BASIS,
26
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- // See the License for the specific language governing permissions and
28
- // limitations under the License.
29
- var _default = exports["default"] = /*#__PURE__*/function () {
30
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(drive, output, logo, colors, font, size, margin) {
31
- var rounded,
32
- credentials,
33
- format,
34
- local,
35
- captionCallback,
36
- result,
37
- folders,
38
- data,
39
- _args = arguments;
40
- return _regeneratorRuntime().wrap(function _callee$(_context) {
41
- while (1) switch (_context.prev = _context.next) {
42
- case 0:
43
- rounded = _args.length > 7 && _args[7] !== undefined ? _args[7] : false;
44
- credentials = _args.length > 8 && _args[8] !== undefined ? _args[8] : null;
45
- format = _args.length > 9 && _args[9] !== undefined ? _args[9] : "PDF";
46
- local = _args.length > 10 && _args[10] !== undefined ? _args[10] : true;
47
- captionCallback = _args.length > 11 && _args[11] !== undefined ? _args[11] : null;
48
- result = [];
49
- if (!drive) {
50
- _context.next = 18;
51
- break;
52
- }
53
- _context.next = 9;
54
- return (0, _folder.list)(drive, credentials);
55
- case 9:
56
- folders = _context.sent;
57
- _context.next = 12;
58
- return (0, _logo.getData)(logo, size);
59
- case 12:
60
- data = _context.sent;
61
- console.info("Processing \"".concat(drive, "\"..."));
62
- _context.next = 16;
63
- return _process(folders, output, size, margin, logo, data, colors, font, rounded, format, local, credentials, captionCallback, result);
64
- case 16:
65
- _context.next = 19;
66
- break;
67
- case 18:
68
- console.error("Source Google Drive or folder is required.");
69
- case 19:
70
- return _context.abrupt("return", result);
71
- case 20:
72
- case "end":
73
- return _context.stop();
74
- }
75
- }, _callee);
76
- }));
77
- return function (_x, _x2, _x3, _x4, _x5, _x6, _x7) {
78
- return _ref.apply(this, arguments);
79
- };
80
- }();
81
- var exists = exports.exists = /*#__PURE__*/function () {
82
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(output, folder, format, local) {
83
- var credentials,
84
- _args2 = arguments;
85
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
86
- while (1) switch (_context2.prev = _context2.next) {
87
- case 0:
88
- credentials = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : null;
89
- if (!local) {
90
- _context2.next = 5;
91
- break;
92
- }
93
- return _context2.abrupt("return", (0, _fs.existsSync)((0, _path.join)(output, (0, _folder.filename)(folder, format))));
94
- case 5:
95
- _context2.next = 7;
96
- return (0, _folder.hasFile)(output, (0, _folder.filename)(folder, format), credentials);
97
- case 7:
98
- return _context2.abrupt("return", _context2.sent);
99
- case 8:
100
- case "end":
101
- return _context2.stop();
102
- }
103
- }, _callee2);
104
- }));
105
- return function exists(_x8, _x9, _x0, _x1) {
106
- return _ref2.apply(this, arguments);
107
- };
108
- }();
109
- var _process = exports.process = /*#__PURE__*/function () {
110
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(folders, output, size, margin, logo, data, colors, font, rounded, format, local, credentials, captionCallback, result) {
111
- var index,
112
- folder,
113
- qr,
114
- _args3 = arguments;
115
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
116
- while (1) switch (_context3.prev = _context3.next) {
117
- case 0:
118
- index = _args3.length > 14 && _args3[14] !== undefined ? _args3[14] : 0;
119
- if (!(typeof folders[index] !== "undefined")) {
120
- _context3.next = 29;
121
- break;
122
- }
123
- folder = folders[index];
124
- _context3.prev = 3;
125
- _context3.next = 6;
126
- return exists(output, folder, format, local, credentials);
127
- case 6:
128
- if (_context3.sent) {
129
- _context3.next = 22;
130
- break;
131
- }
132
- qr = new _image["default"](folder, size, margin, logo, data, colors, font, rounded, typeof captionCallback === "function" ? captionCallback(folder) : folder.name);
133
- console.info("Creating QR code for \"".concat(folder.name, "\"."));
134
- if (!local) {
135
- _context3.next = 17;
136
- break;
137
- }
138
- _context3.t0 = result;
139
- _context3.next = 13;
140
- return qr.save(output, format);
141
- case 13:
142
- _context3.t1 = _context3.sent;
143
- _context3.t0.push.call(_context3.t0, _context3.t1);
144
- _context3.next = 22;
145
- break;
146
- case 17:
147
- _context3.t2 = result;
148
- _context3.next = 20;
149
- return qr.upload(output, format, credentials);
150
- case 20:
151
- _context3.t3 = _context3.sent;
152
- _context3.t2.push.call(_context3.t2, _context3.t3);
153
- case 22:
154
- _context3.next = 24;
155
- return _process(folders, output, size, margin, logo, data, colors, font, rounded, format, local, credentials, captionCallback, result, index + 1);
156
- case 24:
157
- _context3.next = 29;
158
- break;
159
- case 26:
160
- _context3.prev = 26;
161
- _context3.t4 = _context3["catch"](3);
162
- console.error("Error creating QR code for \"".concat(folder.name, "\"."), _context3.t4);
163
- case 29:
164
- case "end":
165
- return _context3.stop();
166
- }
167
- }, _callee3, null, [[3, 26]]);
168
- }));
169
- return function process(_x10, _x11, _x12, _x13, _x14, _x15, _x16, _x17, _x18, _x19, _x20, _x21, _x22, _x23) {
170
- return _ref3.apply(this, arguments);
171
- };
172
- }();