savim-googledrive
Advanced tools
Comparing version 1.0.25 to 1.0.26
@@ -370,2 +370,12 @@ 'use strict'; | ||
//Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions | ||
function escapeRegExp(string) { | ||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
} | ||
function replaceAll(str, match, replacement) { | ||
return str.replace(new RegExp(escapeRegExp(match), 'g'), function () { | ||
return replacement; | ||
}); | ||
} | ||
var resolvePathToGetFolderId = /*#__PURE__*/function () { | ||
@@ -392,3 +402,3 @@ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(client, path) { | ||
return client.files.list({ | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + folderName.replaceAll("'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + replaceAll(folderName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
fields: 'files(id, name)' | ||
@@ -443,3 +453,3 @@ }); | ||
return client.files.list({ | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + folderName.replaceAll("'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + replaceAll(folderName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
fields: 'files(id, name)' | ||
@@ -462,3 +472,3 @@ }); | ||
return client.files.list({ | ||
q: "trashed = false and name = '" + fileName.replaceAll("'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
q: "trashed = false and name = '" + replaceAll(fileName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
fields: 'files(id, name)' | ||
@@ -465,0 +475,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("googleapis");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new O(n||[]);return i(o,"_invoke",{value:k(t,r,a)}),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function d(){}function v(){}var y={};c(y,a,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(_([])));g&&g!==r&&n.call(g,a)&&(y=g);var w=v.prototype=h.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var r;i(this,"_invoke",{value:function(i,o){function a(){return new e((function(r,a){!function r(i,o,a,u){var s=f(t[i],t,o);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){c.value=t,a(c)}),(function(t){return r("throw",t,a,u)}))}u(s.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}})}function k(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var u=L(a,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=f(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===p)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=f(n,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,p;var o=i.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function _(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:F}}function F(){return{value:void 0,done:!0}}return d.prototype=v,i(w,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:d,configurable:!0}),d.displayName=c(v,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,c(t,s,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),c(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new b(l(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(w),c(w,s,"Generator"),c(w,a,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),s=n.call(o,"finallyLoc");if(u&&s){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(a)},complete:function(t,e){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&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;j(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function r(t,e,r,n,i,o,a){try{var u=t[o](a),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,i)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(i,o){var a=t.apply(e,n);function u(t){r(a,i,o,u,s,"next",t)}function s(t){r(a,i,o,u,s,"throw",t)}u(void 0)}))}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a=function(){var t=n(e().mark((function t(r,n){var i,a,u,s,c,l;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=1!==(i=n.substring(1).split("/")).length?i.slice(0,-1):[],u=o(i);case 3:if((s=u()).done){t.next=13;break}return c=s.value,t.next=7,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+c.replaceAll("'","'\"'\"'")+"'"+(a?" and '"+a+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 7:if((l=t.sent).data.files&&0!==l.data.files.length){t.next=10;break}throw new Error("Folder '"+c+"' not found");case 10:a=l.data.files[0].id;case 11:t.next=3;break;case 13:return t.abrupt("return",a);case 14:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),u=function(){var t=n(e().mark((function t(r,n){var i,a,u,s,c,l,f,p;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:1!==(i=n.substring(1).split("/")).length?(a=i[i.length-1],i=i.slice(0,-1)):(a=i,i=[]),s=o(i);case 3:if((c=s()).done){t.next=13;break}return l=c.value,t.next=7,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+l.replaceAll("'","'\"'\"'")+"'"+(u?" and '"+u+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 7:if((f=t.sent).data.files&&0!==f.data.files.length){t.next=10;break}throw new Error("Folder '"+l+"' not found");case 10:u=f.data.files[0].id;case 11:t.next=3;break;case 13:return t.next=15,r.files.list({q:"trashed = false and name = '"+a.replaceAll("'","'\"'\"'")+"'"+(u?" and '"+u+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 15:if((p=t.sent.data.files)&&0!==p.length){t.next=19;break}throw new Error("File '"+a+"' not found");case 19:return t.abrupt("return",p[0].id);case 20:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),s=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return 1!==(n=r.substring(1).split("/")).length?(i=n[n.length-1],n=n.slice(0,-1)):(i=n[0],n=[]),t.abrupt("return",i);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();function c(t){var e=[];return new Promise((function(r,n){t.on("data",(function(t){return e.push(Buffer.from(t))})),t.on("error",(function(t){return n(t)})),t.on("end",(function(){return r(Buffer.concat(e).toString("base64"))}))}))}exports.SavimGoogleDriveProvider=function(){function r(e){this.config=e,this.name="google-drive",this.client=t.google.drive({version:"v3",auth:e})}var i=r.prototype;return i.isHealthy=function(){var t=n(e().mark((function t(){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.drives.list();case 3:return t.abrupt("return",!0);case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",!1);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(){return t.apply(this,arguments)}}(),i.getFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,u(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.get({fileId:n,alt:"media",acknowledgeAbuse:!0},{responseType:"stream"});case 5:return t.abrupt("return",c(t.sent.data));case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.uploadFile=function(){var t=n(e().mark((function t(r,n,i){var o,u;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=3,s(r);case 3:return o=t.sent,t.next=6,a(this.client,r);case 6:return u=t.sent,t.next=9,this.client.files.create({requestBody:{name:o,parents:[u]},media:{body:n}});case 9:return t.abrupt("return",t.sent.data.id);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),i.deleteFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,u(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.createFolder=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(r);case 2:return n=t.sent,t.next=5,a(this.client,r);case 5:return i=t.sent,t.next=8,this.client.files.create({requestBody:{name:n,mimeType:"application/vnd.google-apps.folder",parents:i?[i]:[]},fields:"id, name"});case 8:return t.abrupt("return",t.sent.data.id);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.deleteFolder=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,u(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFolders=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,u(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFiles=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,u(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType != 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r}(); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("googleapis");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new O(n||[]);return i(o,"_invoke",{value:k(t,r,a)}),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function d(){}function v(){}var y={};s(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==r&&n.call(m,a)&&(y=m);var w=v.prototype=h.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var r;i(this,"_invoke",{value:function(i,o){function a(){return new e((function(r,a){!function r(i,o,a,u){var c=f(t[i],t,o);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}})}function k(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var u=L(a,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=f(n,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,p;var o=i.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function _(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:F}}function F(){return{value:void 0,done:!0}}return d.prototype=v,i(w,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),s(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new b(l(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(w),s(w,c,"Generator"),s(w,a,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(a)},complete:function(t,e){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&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;j(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function r(t,e,r,n,i,o,a){try{var u=t[o](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,i)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(i,o){var a=t.apply(e,n);function u(t){r(a,i,o,u,c,"next",t)}function c(t){r(a,i,o,u,c,"throw",t)}u(void 0)}))}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(t,e,r){return t.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),(function(){return r}))}var u=function(){var t=n(e().mark((function t(r,n){var i,u,c,s,l,f;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=1!==(i=n.substring(1).split("/")).length?i.slice(0,-1):[],c=o(i);case 3:if((s=c()).done){t.next=13;break}return l=s.value,t.next=7,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+a(l,"'","'\"'\"'")+"'"+(u?" and '"+u+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 7:if((f=t.sent).data.files&&0!==f.data.files.length){t.next=10;break}throw new Error("Folder '"+l+"' not found");case 10:u=f.data.files[0].id;case 11:t.next=3;break;case 13:return t.abrupt("return",u);case 14:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),c=function(){var t=n(e().mark((function t(r,n){var i,u,c,s,l,f,p,h;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:1!==(i=n.substring(1).split("/")).length?(u=i[i.length-1],i=i.slice(0,-1)):(u=i,i=[]),s=o(i);case 3:if((l=s()).done){t.next=13;break}return f=l.value,t.next=7,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+a(f,"'","'\"'\"'")+"'"+(c?" and '"+c+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 7:if((p=t.sent).data.files&&0!==p.data.files.length){t.next=10;break}throw new Error("Folder '"+f+"' not found");case 10:c=p.data.files[0].id;case 11:t.next=3;break;case 13:return t.next=15,r.files.list({q:"trashed = false and name = '"+a(u,"'","'\"'\"'")+"'"+(c?" and '"+c+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 15:if((h=t.sent.data.files)&&0!==h.length){t.next=19;break}throw new Error("File '"+u+"' not found");case 19:return t.abrupt("return",h[0].id);case 20:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),s=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return 1!==(n=r.substring(1).split("/")).length?(i=n[n.length-1],n=n.slice(0,-1)):(i=n[0],n=[]),t.abrupt("return",i);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();function l(t){var e=[];return new Promise((function(r,n){t.on("data",(function(t){return e.push(Buffer.from(t))})),t.on("error",(function(t){return n(t)})),t.on("end",(function(){return r(Buffer.concat(e).toString("base64"))}))}))}exports.SavimGoogleDriveProvider=function(){function r(e){this.config=e,this.name="google-drive",this.client=t.google.drive({version:"v3",auth:e})}var i=r.prototype;return i.isHealthy=function(){var t=n(e().mark((function t(){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.drives.list();case 3:return t.abrupt("return",!0);case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",!1);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(){return t.apply(this,arguments)}}(),i.getFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.get({fileId:n,alt:"media",acknowledgeAbuse:!0},{responseType:"stream"});case 5:return t.abrupt("return",l(t.sent.data));case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.uploadFile=function(){var t=n(e().mark((function t(r,n,i){var o,a;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=3,s(r);case 3:return o=t.sent,t.next=6,u(this.client,r);case 6:return a=t.sent,t.next=9,this.client.files.create({requestBody:{name:o,parents:[a]},media:{body:n}});case 9:return t.abrupt("return",t.sent.data.id);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),i.deleteFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.createFolder=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(r);case 2:return n=t.sent,t.next=5,u(this.client,r);case 5:return i=t.sent,t.next=8,this.client.files.create({requestBody:{name:n,mimeType:"application/vnd.google-apps.folder",parents:i?[i]:[]},fields:"id, name"});case 8:return t.abrupt("return",t.sent.data.id);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.deleteFolder=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFolders=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,c(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFiles=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,c(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType != 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r}(); | ||
//# sourceMappingURL=savim-googledrive.cjs.production.min.js.map |
@@ -366,2 +366,12 @@ import { google } from 'googleapis'; | ||
//Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions | ||
function escapeRegExp(string) { | ||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
} | ||
function replaceAll(str, match, replacement) { | ||
return str.replace(new RegExp(escapeRegExp(match), 'g'), function () { | ||
return replacement; | ||
}); | ||
} | ||
var resolvePathToGetFolderId = /*#__PURE__*/function () { | ||
@@ -388,3 +398,3 @@ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(client, path) { | ||
return client.files.list({ | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + folderName.replaceAll("'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + replaceAll(folderName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
fields: 'files(id, name)' | ||
@@ -439,3 +449,3 @@ }); | ||
return client.files.list({ | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + folderName.replaceAll("'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + replaceAll(folderName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
fields: 'files(id, name)' | ||
@@ -458,3 +468,3 @@ }); | ||
return client.files.list({ | ||
q: "trashed = false and name = '" + fileName.replaceAll("'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
q: "trashed = false and name = '" + replaceAll(fileName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"), | ||
fields: 'files(id, name)' | ||
@@ -461,0 +471,0 @@ }); |
{ | ||
"version": "1.0.25", | ||
"version": "1.0.26", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -19,2 +19,10 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
//Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions | ||
function escapeRegExp(string: string) { | ||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
} | ||
function replaceAll(str: string, match: string, replacement: string) { | ||
return str.replace(new RegExp(escapeRegExp(match), 'g'), () => replacement); | ||
} | ||
const resolvePathToGetFolderId = async ( | ||
@@ -37,3 +45,7 @@ client: drive_v3.Drive, | ||
const folders = await client.files.list({ | ||
q: `mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '${folderName.replaceAll("'", `'"'"'`)}'${ | ||
q: `mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '${replaceAll( | ||
folderName, | ||
"'", | ||
`'"'"'`, | ||
)}'${ | ||
folderId ? ` and '${folderId}' in parents` : ` and 'root' in parents` | ||
@@ -71,3 +83,7 @@ }`, | ||
const folders = await client.files.list({ | ||
q: `mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '${folderName.replaceAll("'", `'"'"'`)}'${ | ||
q: `mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '${replaceAll( | ||
folderName, | ||
"'", | ||
`'"'"'`, | ||
)}'${ | ||
folderId ? ` and '${folderId}' in parents` : ` and 'root' in parents` | ||
@@ -86,3 +102,7 @@ }`, | ||
const res = await client.files.list({ | ||
q: `trashed = false and name = '${(fileName as string).replaceAll("'", `'"'"'`)}'${ | ||
q: `trashed = false and name = '${replaceAll( | ||
fileName as string, | ||
"'", | ||
`'"'"'`, | ||
)}'${ | ||
folderId ? ` and '${folderId}' in parents` : ` and 'root' in parents` | ||
@@ -89,0 +109,0 @@ }`, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
147410
1909