restafary 13.0.0 → 13.0.2
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/ChangeLog +10 -0
- package/README.md +12 -13
- package/client/index.js +7 -8
- package/dist/restafary.js +1 -1
- package/dist/restafary.js.map +1 -1
- package/dist-dev/restafary.js +31 -28
- package/package.json +3 -3
- package/server/fs/get.js +19 -12
- package/server/fs/patch.js +6 -9
- package/server/fs/put.js +4 -7
- package/server/fs/{delete.js → remove.js} +7 -11
- package/server/handle-dot-dir.js +2 -4
- package/server/restafary.js +36 -33
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Restafary [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
|
|
2
2
|
|
|
3
|
+
[NPMIMGURL]: https://img.shields.io/npm/v/restafary.svg?style=flat
|
|
4
|
+
[BuildStatusURL]: https://github.com/coderaiser/node-restafary/actions?query=workflow%3A%22Node+CI%22 "Build Status"
|
|
5
|
+
[BuildStatusIMGURL]: https://github.com/coderaiser/node-restafary/workflows/Node%20CI/badge.svg
|
|
6
|
+
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
|
|
7
|
+
[NPMURL]: https://npmjs.org/package/restafary "npm"
|
|
8
|
+
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
|
|
9
|
+
|
|
3
10
|
**REST** for **CRUD** file operations.
|
|
4
11
|
|
|
5
12
|
## What is it?
|
|
@@ -18,12 +25,12 @@
|
|
|
18
25
|
|:------------|:--------|:--------------|:------------------|:------------------------------|
|
|
19
26
|
|`fs` |`GET` | | |get file or dir content |
|
|
20
27
|
| | |`sort` | |sort dir content by `name`, |
|
|
21
|
-
| | | | |`size` or `
|
|
28
|
+
| | | | |`size` or `date` |
|
|
22
29
|
| | |`order` | |order of sorting, can be: |
|
|
23
30
|
| | | | |`asc` or `desc` |
|
|
24
31
|
| | |`raw` | |get file or raw dir content |
|
|
25
32
|
| | |`size` | |get file or dir size |
|
|
26
|
-
| | |`raw-size`
|
|
33
|
+
| | |`raw-size` | |get raw size |
|
|
27
34
|
| | |`hash` | |get file hash |
|
|
28
35
|
| | |`download` | |content disposition attachment |
|
|
29
36
|
| |`PUT` | |file content |create/write file |
|
|
@@ -36,10 +43,9 @@
|
|
|
36
43
|
## How to use?
|
|
37
44
|
|
|
38
45
|
```js
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const express = require('express');
|
|
46
|
+
import http from 'node:http';
|
|
47
|
+
import {restafary} from 'restafary';
|
|
48
|
+
import express from 'express';
|
|
43
49
|
|
|
44
50
|
const app = express();
|
|
45
51
|
const server = http.createServer(app);
|
|
@@ -59,10 +65,3 @@ server.listen(port, ip);
|
|
|
59
65
|
## License
|
|
60
66
|
|
|
61
67
|
MIT
|
|
62
|
-
|
|
63
|
-
[NPMIMGURL]: https://img.shields.io/npm/v/restafary.svg?style=flat
|
|
64
|
-
[BuildStatusURL]: https://github.com/coderaiser/node-restafary/actions?query=workflow%3A%22Node+CI%22 "Build Status"
|
|
65
|
-
[BuildStatusIMGURL]: https://github.com/coderaiser/node-restafary/workflows/Node%20CI/badge.svg
|
|
66
|
-
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
|
|
67
|
-
[NPMURL]: https://npmjs.org/package/restafary "npm"
|
|
68
|
-
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
|
package/client/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
let FS = '/api/v1/fs';
|
|
4
2
|
const isFn = (a) => typeof a === 'function';
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
export const prefix = (prefix) => {
|
|
7
5
|
FS = prefix;
|
|
8
6
|
};
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export const remove = (url, data, callback) => {
|
|
11
9
|
if (!callback && isFn(data)) {
|
|
12
10
|
callback = data;
|
|
13
11
|
data = null;
|
|
@@ -21,7 +19,7 @@ module.exports.delete = (url, data, callback) => {
|
|
|
21
19
|
});
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
export const patch = (url, data, callback) => {
|
|
25
23
|
if (!callback && isFn(data)) {
|
|
26
24
|
callback = data;
|
|
27
25
|
data = null;
|
|
@@ -35,7 +33,7 @@ module.exports.patch = (url, data, callback) => {
|
|
|
35
33
|
});
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
export const write = (url, data, callback) => {
|
|
39
37
|
if (!callback && isFn(data)) {
|
|
40
38
|
callback = data;
|
|
41
39
|
data = null;
|
|
@@ -49,7 +47,7 @@ module.exports.write = (url, data, callback) => {
|
|
|
49
47
|
});
|
|
50
48
|
};
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
export const read = (url, callback) => {
|
|
53
51
|
sendRequest({
|
|
54
52
|
method: 'GET',
|
|
55
53
|
url: FS + url,
|
|
@@ -65,7 +63,8 @@ function sendRequest({url, data, method, callback}) {
|
|
|
65
63
|
* when we send ajax request -
|
|
66
64
|
* no need in hash so we escape #
|
|
67
65
|
*/
|
|
68
|
-
|
|
66
|
+
export const _escape = escape;
|
|
67
|
+
|
|
69
68
|
function escape(str) {
|
|
70
69
|
return encodeURI(str).replace(/#/g, '%23');
|
|
71
70
|
}
|
package/dist/restafary.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.restafary=t():e.restafary=t()}(globalThis,()=>(()=>{"use strict";var e={
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.restafary=t():e.restafary=t()}(globalThis,()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{_escape:()=>s,patch:()=>l,prefix:()=>a,read:()=>c,remove:()=>n,write:()=>d});let o="/api/v1/fs";const r=e=>"function"==typeof e,a=e=>{o=e},n=(e,t,a)=>{!a&&r(t)&&(a=t,t=null),u({method:"DELETE",url:o+e,data:t,callback:a})},l=(e,t,a)=>{!a&&r(t)&&(a=t,t=null),u({method:"PATCH",url:o+e,data:t,callback:a})},d=(e,t,a)=>{!a&&r(t)&&(a=t,t=null),u({method:"PUT",url:o+e,data:t,callback:a})},c=(e,t)=>{u({method:"GET",url:o+e,callback:t})};function u({url:e,data:t,method:o,callback:a}){!function(e,t){const{url:o,data:a,method:n}=e,l=new XMLHttpRequest;if(!r(t))throw Error("Callback should be function!");l.open(n,o,!0),l.addEventListener("error",t),l.addEventListener("load",()=>{if(l.status>=200&&l.status<400)return t(null,l.responseText);t(Error(l.responseText))}),l.send(a)}({method:o,data:t,url:f(e)},a)}const s=f;function f(e){return encodeURI(e).replace(/#/g,"%23")}return t})());
|
|
2
2
|
//# sourceMappingURL=restafary.js.map
|
package/dist/restafary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restafary.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAmB,UAAID,IAEvBD,EAAgB,UAAIC,GACrB,CATD,CASGK,WAAY,I,
|
|
1
|
+
{"version":3,"file":"restafary.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAmB,UAAID,IAEvBD,EAAgB,UAAIC,GACrB,CATD,CASGK,WAAY,I,mBCRf,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,M,gGCLvD,IAAIC,EAAK,aACT,MAAMC,EAAQC,GAAmB,mBAANA,EAEdC,EAAUA,IACnBH,EAAKG,GAGIC,EAASA,CAACC,EAAKC,EAAMC,MACzBA,GAAYN,EAAKK,KAClBC,EAAWD,EACXA,EAAO,MAGXE,EAAY,CACRC,OAAQ,SACRJ,IAAKL,EAAKK,EACVC,OACAC,cAIKG,EAAQA,CAACL,EAAKC,EAAMC,MACxBA,GAAYN,EAAKK,KAClBC,EAAWD,EACXA,EAAO,MAGXE,EAAY,CACRC,OAAQ,QACRJ,IAAKL,EAAKK,EACVC,OACAC,cAIKI,EAAQA,CAACN,EAAKC,EAAMC,MACxBA,GAAYN,EAAKK,KAClBC,EAAWD,EACXA,EAAO,MAGXE,EAAY,CACRC,OAAQ,MACRJ,IAAKL,EAAKK,EACVC,OACAC,cAIKK,EAAOA,CAACP,EAAKE,KACtBC,EAAY,CACRC,OAAQ,MACRJ,IAAKL,EAAKK,EACVE,cAIR,SAASC,GAAY,IAACH,EAAG,KAAEC,EAAI,OAAEG,EAAM,SAAEF,KAczC,SAAcM,EAAQN,GAClB,MAAM,IACFF,EAAG,KACHC,EAAI,OACJG,GACAI,EAEEC,EAAU,IAAIC,eAEpB,IAAKd,EAAKM,GACN,MAAMS,MAAM,gCAShBF,EAAQG,KAAKR,EAAQJ,GAAK,GAC1BS,EAAQI,iBAAiB,QAASX,GAClCO,EAAQI,iBAAiB,OATZC,KACT,GAAIL,EAAQM,QAAU,KAAON,EAAQM,OAAS,IAC1C,OAAOb,EAAS,KAAMO,EAAQO,cAElCd,EAASS,MAAMF,EAAQO,iBAO3BP,EAAQQ,KAAKhB,EACjB,CArCIiB,CAAK,CAACd,SAAQH,OAAMD,IAAKmB,EAAOnB,IAAOE,EAC3C,CAMO,MAAMkB,EAAUD,EAEvB,SAASA,EAAOE,GACZ,OAAOC,UAAUD,GAAKE,QAAQ,KAAM,MACxC,C","sources":["file://restafary/webpack/universalModuleDefinition","file://restafary/webpack/bootstrap","file://restafary/webpack/runtime/define property getters","file://restafary/webpack/runtime/hasOwnProperty shorthand","file://restafary/webpack/runtime/make namespace object","file://restafary/client/index.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"restafary\"] = factory();\n\telse\n\t\troot[\"restafary\"] = factory();\n})(globalThis, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","let FS = '/api/v1/fs';\nconst isFn = (a) => typeof a === 'function';\n\nexport const prefix = (prefix) => {\n FS = prefix;\n};\n\nexport const remove = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'DELETE',\n url: FS + url,\n data,\n callback,\n });\n};\n\nexport const patch = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PATCH',\n url: FS + url,\n data,\n callback,\n });\n};\n\nexport const write = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PUT',\n url: FS + url,\n data,\n callback,\n });\n};\n\nexport const read = (url, callback) => {\n sendRequest({\n method: 'GET',\n url: FS + url,\n callback,\n });\n};\n\nfunction sendRequest({url, data, method, callback}) {\n ajax({method, data, url: escape(url)}, callback);\n}\n\n/*\n * when we send ajax request -\n * no need in hash so we escape #\n */\nexport const _escape = escape;\n\nfunction escape(str) {\n return encodeURI(str).replace(/#/g, '%23');\n}\n\nfunction ajax(params, callback) {\n const {\n url,\n data,\n method,\n } = params;\n \n const request = new XMLHttpRequest();\n \n if (!isFn(callback))\n throw Error('Callback should be function!');\n \n const load = () => {\n if (request.status >= 200 && request.status < 400)\n return callback(null, request.responseText);\n \n callback(Error(request.responseText));\n };\n \n request.open(method, url, true);\n request.addEventListener('error', callback);\n request.addEventListener('load', load);\n \n request.send(data);\n}\n"],"names":["root","factory","exports","module","define","amd","globalThis","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","FS","isFn","a","prefix","remove","url","data","callback","sendRequest","method","patch","write","read","params","request","XMLHttpRequest","Error","open","addEventListener","load","status","responseText","send","ajax","escape","_escape","str","encodeURI","replace"],"sourceRoot":""}
|
package/dist-dev/restafary.js
CHANGED
|
@@ -24,50 +24,53 @@ return /******/ (() => { // webpackBootstrap
|
|
|
24
24
|
/*!*************************!*\
|
|
25
25
|
!*** ./client/index.js ***!
|
|
26
26
|
\*************************/
|
|
27
|
-
(
|
|
27
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
28
28
|
|
|
29
|
-
eval("{\n\nlet FS = '/api/v1/fs';\nconst isFn = (a) => typeof a === 'function';\n\
|
|
29
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ _escape: () => (/* binding */ _escape),\n/* harmony export */ patch: () => (/* binding */ patch),\n/* harmony export */ prefix: () => (/* binding */ prefix),\n/* harmony export */ read: () => (/* binding */ read),\n/* harmony export */ remove: () => (/* binding */ remove),\n/* harmony export */ write: () => (/* binding */ write)\n/* harmony export */ });\nlet FS = '/api/v1/fs';\nconst isFn = (a) => typeof a === 'function';\n\nconst prefix = (prefix) => {\n FS = prefix;\n};\n\nconst remove = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'DELETE',\n url: FS + url,\n data,\n callback,\n });\n};\n\nconst patch = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PATCH',\n url: FS + url,\n data,\n callback,\n });\n};\n\nconst write = (url, data, callback) => {\n if (!callback && isFn(data)) {\n callback = data;\n data = null;\n }\n \n sendRequest({\n method: 'PUT',\n url: FS + url,\n data,\n callback,\n });\n};\n\nconst read = (url, callback) => {\n sendRequest({\n method: 'GET',\n url: FS + url,\n callback,\n });\n};\n\nfunction sendRequest({url, data, method, callback}) {\n ajax({method, data, url: escape(url)}, callback);\n}\n\n/*\n * when we send ajax request -\n * no need in hash so we escape #\n */\nconst _escape = escape;\n\nfunction escape(str) {\n return encodeURI(str).replace(/#/g, '%23');\n}\n\nfunction ajax(params, callback) {\n const {\n url,\n data,\n method,\n } = params;\n \n const request = new XMLHttpRequest();\n \n if (!isFn(callback))\n throw Error('Callback should be function!');\n \n const load = () => {\n if (request.status >= 200 && request.status < 400)\n return callback(null, request.responseText);\n \n callback(Error(request.responseText));\n };\n \n request.open(method, url, true);\n request.addEventListener('error', callback);\n request.addEventListener('load', load);\n \n request.send(data);\n}\n\n\n//# sourceURL=file://restafary/client/index.js\n}");
|
|
30
30
|
|
|
31
31
|
/***/ }
|
|
32
32
|
|
|
33
33
|
/******/ });
|
|
34
34
|
/************************************************************************/
|
|
35
|
-
/******/ // The
|
|
36
|
-
/******/ var
|
|
35
|
+
/******/ // The require scope
|
|
36
|
+
/******/ var __webpack_require__ = {};
|
|
37
37
|
/******/
|
|
38
|
-
|
|
39
|
-
/******/
|
|
40
|
-
/******/
|
|
41
|
-
/******/
|
|
42
|
-
/******/
|
|
43
|
-
/******/
|
|
44
|
-
/******/
|
|
45
|
-
/******/
|
|
46
|
-
/******/
|
|
47
|
-
/******/
|
|
48
|
-
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
49
|
-
/******/ throw e;
|
|
50
|
-
/******/ }
|
|
51
|
-
/******/ // Create a new module (and put it into the cache)
|
|
52
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
53
|
-
/******/ // no module.id needed
|
|
54
|
-
/******/ // no module.loaded needed
|
|
55
|
-
/******/ exports: {}
|
|
38
|
+
/************************************************************************/
|
|
39
|
+
/******/ /* webpack/runtime/define property getters */
|
|
40
|
+
/******/ (() => {
|
|
41
|
+
/******/ // define getter functions for harmony exports
|
|
42
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
43
|
+
/******/ for(var key in definition) {
|
|
44
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
45
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
46
|
+
/******/ }
|
|
47
|
+
/******/ }
|
|
56
48
|
/******/ };
|
|
49
|
+
/******/ })();
|
|
57
50
|
/******/
|
|
58
|
-
/******/
|
|
59
|
-
/******/
|
|
51
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
52
|
+
/******/ (() => {
|
|
53
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
54
|
+
/******/ })();
|
|
60
55
|
/******/
|
|
61
|
-
/******/
|
|
62
|
-
/******/
|
|
63
|
-
/******/
|
|
56
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
57
|
+
/******/ (() => {
|
|
58
|
+
/******/ // define __esModule on exports
|
|
59
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
60
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
61
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
62
|
+
/******/ }
|
|
63
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
64
|
+
/******/ };
|
|
65
|
+
/******/ })();
|
|
64
66
|
/******/
|
|
65
67
|
/************************************************************************/
|
|
66
68
|
/******/
|
|
67
69
|
/******/ // startup
|
|
68
70
|
/******/ // Load entry module and return exports
|
|
69
71
|
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
70
|
-
/******/ var __webpack_exports__ =
|
|
72
|
+
/******/ var __webpack_exports__ = {};
|
|
73
|
+
/******/ __webpack_modules__["./client/index.js"](0,__webpack_exports__,__webpack_require__);
|
|
71
74
|
/******/
|
|
72
75
|
/******/ return __webpack_exports__;
|
|
73
76
|
/******/ })()
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "restafary",
|
|
3
|
-
"version": "13.0.
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "13.0.2",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"description": "REST for CRUD file operations",
|
|
6
6
|
"main": "server/restafary.js",
|
|
7
7
|
"engines": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"jonny": "^3.0.0",
|
|
45
45
|
"mellow": "^3.0.1",
|
|
46
46
|
"mime-types": "^3.0.2",
|
|
47
|
-
"patchfile": "^
|
|
47
|
+
"patchfile": "^5.0.0",
|
|
48
48
|
"pipe-io": "^4.0.1",
|
|
49
49
|
"ponse": "^7.0.0",
|
|
50
50
|
"pullout": "^5.0.1",
|
package/server/fs/get.js
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const ashify = require('ashify');
|
|
9
|
-
const {read} = require('win32');
|
|
10
|
-
const {readSize} = require('redzip');
|
|
1
|
+
import {Buffer} from 'node:buffer';
|
|
2
|
+
import {Readable} from 'node:stream';
|
|
3
|
+
import {parse} from 'node:querystring';
|
|
4
|
+
import check from 'checkup';
|
|
5
|
+
import ashify from 'ashify';
|
|
6
|
+
import {read as _read} from 'win32';
|
|
7
|
+
import {readSize} from 'redzip';
|
|
11
8
|
|
|
12
9
|
const {assign} = Object;
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
export const get = async (overrides = {}) => {
|
|
12
|
+
const {
|
|
13
|
+
query,
|
|
14
|
+
path,
|
|
15
|
+
root,
|
|
16
|
+
read = _read,
|
|
17
|
+
} = overrides;
|
|
18
|
+
|
|
15
19
|
check
|
|
16
20
|
.type('path', path, 'string')
|
|
17
21
|
.check({
|
|
18
22
|
query,
|
|
19
23
|
});
|
|
20
24
|
|
|
21
|
-
const {
|
|
25
|
+
const {
|
|
26
|
+
sort = 'name',
|
|
27
|
+
order = 'asc',
|
|
28
|
+
} = parse(query);
|
|
22
29
|
|
|
23
30
|
switch(query) {
|
|
24
31
|
default:
|
package/server/fs/patch.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import {callbackify} from 'node:util';
|
|
2
|
+
import check from 'checkup';
|
|
3
|
+
import pullout from 'pullout';
|
|
4
|
+
import {patchfile} from 'patchfile';
|
|
2
5
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const check = require('checkup');
|
|
6
|
-
const pullout = require('pullout');
|
|
7
|
-
const patch = require('patchfile');
|
|
8
|
-
|
|
9
|
-
module.exports = callbackify(async (name, readStream, options) => {
|
|
6
|
+
export const patch = callbackify(async (name, readStream, options) => {
|
|
10
7
|
check
|
|
11
8
|
.type('name', name, 'string')
|
|
12
9
|
.type('readStream', readStream, 'object');
|
|
13
10
|
|
|
14
11
|
const data = await pullout(readStream, 'string');
|
|
15
12
|
|
|
16
|
-
return
|
|
13
|
+
return patchfile(name, data, options);
|
|
17
14
|
});
|
package/server/fs/put.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {callbackify} from 'node:util';
|
|
2
|
+
import check from 'checkup';
|
|
3
|
+
import {write} from 'redzip';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const check = require('checkup');
|
|
6
|
-
const {write} = require('redzip');
|
|
7
|
-
|
|
8
|
-
module.exports = callbackify(async (query, name, readStream) => {
|
|
5
|
+
export const put = callbackify(async (query, name, readStream) => {
|
|
9
6
|
check
|
|
10
7
|
.type('name', name, 'string')
|
|
11
8
|
.type('readStream', readStream, 'object')
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import check from 'checkup';
|
|
2
|
+
import {remove as flopRemove} from 'flop';
|
|
3
|
+
import pullout from 'pullout';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const check = require('checkup');
|
|
5
|
-
const {remove} = require('flop');
|
|
6
|
-
|
|
7
|
-
const pullout = require('pullout');
|
|
8
|
-
|
|
9
|
-
module.exports = callbackify(async (query, name, readStream) => {
|
|
5
|
+
export const remove = async (query, name, readStream) => {
|
|
10
6
|
check
|
|
11
7
|
.type('name', name, 'string')
|
|
12
8
|
.type('readStream', readStream, 'object')
|
|
@@ -15,12 +11,12 @@ module.exports = callbackify(async (query, name, readStream) => {
|
|
|
15
11
|
});
|
|
16
12
|
|
|
17
13
|
if (query !== 'files')
|
|
18
|
-
return await
|
|
14
|
+
return await flopRemove(name);
|
|
19
15
|
|
|
20
16
|
const files = await getBody(readStream);
|
|
21
17
|
|
|
22
|
-
await
|
|
23
|
-
}
|
|
18
|
+
await flopRemove(name, files);
|
|
19
|
+
};
|
|
24
20
|
|
|
25
21
|
async function getBody(readStream) {
|
|
26
22
|
const data = await pullout(readStream, 'string');
|
package/server/handle-dot-dir.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {join} from 'node:path';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.handleDotFolder = (root, cwd) => {
|
|
3
|
+
export const handleDotFolder = (root, cwd) => {
|
|
6
4
|
if (root.startsWith('./')) {
|
|
7
5
|
root = root.replace('./', '');
|
|
8
6
|
return join(cwd, root);
|
package/server/restafary.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import {fileURLToPath} from 'node:url';
|
|
3
|
+
import {
|
|
6
4
|
basename,
|
|
7
5
|
extname,
|
|
8
6
|
join,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
dirname,
|
|
8
|
+
} from 'node:path';
|
|
9
|
+
import {webToWin} from 'mellow';
|
|
10
|
+
import ponse from 'ponse';
|
|
11
|
+
import currify from 'currify';
|
|
12
|
+
import {tryToCatch as _tryToCatch} from 'try-to-catch';
|
|
13
|
+
import pipe from 'pipe-io';
|
|
14
|
+
import {contentType} from 'mime-types';
|
|
15
|
+
import {fileTypeStream} from 'file-type';
|
|
16
|
+
import {handleDotFolder} from './handle-dot-dir.js';
|
|
17
|
+
import {get} from './fs/get.js';
|
|
18
|
+
import {put} from './fs/put.js';
|
|
19
|
+
import {patch} from './fs/patch.js';
|
|
20
|
+
import {remove} from './fs/remove.js';
|
|
12
21
|
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const {tryToCatch: _tryToCatch} = require('try-to-catch');
|
|
16
|
-
const pipe = require('pipe-io');
|
|
17
|
-
const {contentType} = require('mime-types');
|
|
18
|
-
const {handleDotFolder} = require('./handle-dot-dir');
|
|
22
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
23
|
+
const __dirname = dirname(__filename);
|
|
19
24
|
const isUndefined = (a) => typeof a === 'undefined';
|
|
20
25
|
const isFn = (a) => typeof a === 'function';
|
|
21
|
-
|
|
22
|
-
const DIR = './';
|
|
23
26
|
const WIN = process.platform === 'win32';
|
|
24
27
|
const CWD = process.cwd();
|
|
25
|
-
const Fs = {};
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Fs[name] = require(DIR + 'fs/' + name);
|
|
34
|
-
}
|
|
29
|
+
const Fs = {
|
|
30
|
+
get,
|
|
31
|
+
put,
|
|
32
|
+
patch,
|
|
33
|
+
remove,
|
|
34
|
+
};
|
|
35
35
|
|
|
36
36
|
const isDev = process.env.NODE_ENV === 'development';
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
export const restafary = currify(async (options, request, response, next) => {
|
|
39
39
|
const req = request;
|
|
40
40
|
const res = response;
|
|
41
41
|
const isFile = /^\/restafary\.js(\.map)?$/.test(req.url);
|
|
@@ -44,6 +44,7 @@ module.exports = currify(async (options, request, response, next) => {
|
|
|
44
44
|
prefix = '/fs',
|
|
45
45
|
root = '/',
|
|
46
46
|
tryToCatch = _tryToCatch,
|
|
47
|
+
read,
|
|
47
48
|
} = options;
|
|
48
49
|
|
|
49
50
|
const params = {
|
|
@@ -51,6 +52,7 @@ module.exports = currify(async (options, request, response, next) => {
|
|
|
51
52
|
request,
|
|
52
53
|
response,
|
|
53
54
|
tryToCatch,
|
|
55
|
+
read,
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
let name = ponse.getPathName(req);
|
|
@@ -132,7 +134,7 @@ function checkPath(name, root) {
|
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
async function onFS(params, callback) {
|
|
135
|
-
const {tryToCatch} = params;
|
|
137
|
+
const {tryToCatch, read} = params;
|
|
136
138
|
const pathError = 'Could not write file/create directory in root on windows!';
|
|
137
139
|
const p = params;
|
|
138
140
|
const {name} = p;
|
|
@@ -179,10 +181,12 @@ async function onFS(params, callback) {
|
|
|
179
181
|
callback(error, optionsDefaults);
|
|
180
182
|
});
|
|
181
183
|
|
|
182
|
-
case 'DELETE':
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
case 'DELETE': {
|
|
185
|
+
const [error] = await tryToCatch(Fs.remove, query, pathOS, p.request);
|
|
186
|
+
|
|
187
|
+
callback(error, optionsDefaults);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
186
190
|
|
|
187
191
|
case 'HEAD':
|
|
188
192
|
case 'GET': {
|
|
@@ -190,6 +194,7 @@ async function onFS(params, callback) {
|
|
|
190
194
|
query,
|
|
191
195
|
path: pathOS,
|
|
192
196
|
root,
|
|
197
|
+
read,
|
|
193
198
|
});
|
|
194
199
|
|
|
195
200
|
if (error)
|
|
@@ -232,8 +237,6 @@ function format(msg, name) {
|
|
|
232
237
|
}
|
|
233
238
|
|
|
234
239
|
async function getContentType({type, pathWeb, stream, tryToCatch}) {
|
|
235
|
-
const {fileTypeStream} = await import('file-type');
|
|
236
|
-
|
|
237
240
|
if (!type)
|
|
238
241
|
return [null, stream, 'text/plain'];
|
|
239
242
|
|