@ruiapp/rapid-core 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { default as EntityManager } from "./dataAccess/entityManager";
|
|
|
13
13
|
export * from "./dataAccess/entityManager";
|
|
14
14
|
export * from "./utilities/accessControlUtility";
|
|
15
15
|
export * from "./utilities/entityUtility";
|
|
16
|
+
export * from "./utilities/fsUtility";
|
|
16
17
|
export * from "./utilities/jwtUtility";
|
|
17
18
|
export * from "./utilities/timeUtility";
|
|
18
19
|
export * from "./utilities/passwordUtility";
|
package/dist/index.js
CHANGED
|
@@ -7,11 +7,11 @@ var events = require('events');
|
|
|
7
7
|
var Router = require('koa-tree-router');
|
|
8
8
|
var qs = require('qs');
|
|
9
9
|
var dayjs = require('dayjs');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var path = require('path');
|
|
10
12
|
var jsonwebtoken = require('jsonwebtoken');
|
|
11
13
|
var crypto = require('crypto');
|
|
12
14
|
var bcrypt = require('bcryptjs');
|
|
13
|
-
var path = require('path');
|
|
14
|
-
var fs = require('fs');
|
|
15
15
|
var uuid = require('uuid');
|
|
16
16
|
var nodemailer = require('nodemailer');
|
|
17
17
|
var cron = require('cron');
|
|
@@ -22,10 +22,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
22
22
|
var Router__default = /*#__PURE__*/_interopDefaultLegacy(Router);
|
|
23
23
|
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
24
24
|
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
25
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
26
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
25
27
|
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
26
28
|
var bcrypt__default = /*#__PURE__*/_interopDefaultLegacy(bcrypt);
|
|
27
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
28
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
29
29
|
var nodemailer__default = /*#__PURE__*/_interopDefaultLegacy(nodemailer);
|
|
30
30
|
|
|
31
31
|
function fixBigIntJSONSerialize() {
|
|
@@ -4941,6 +4941,128 @@ function getEntityRelationTargetId(entity, propName, targetColumnName) {
|
|
|
4941
4941
|
}
|
|
4942
4942
|
}
|
|
4943
4943
|
|
|
4944
|
+
async function readFile(path) {
|
|
4945
|
+
return new Promise((resolve, reject) => {
|
|
4946
|
+
fs__default["default"].readFile(path, null, (err, data) => {
|
|
4947
|
+
if (err) {
|
|
4948
|
+
reject(err);
|
|
4949
|
+
}
|
|
4950
|
+
else {
|
|
4951
|
+
resolve(data);
|
|
4952
|
+
}
|
|
4953
|
+
});
|
|
4954
|
+
});
|
|
4955
|
+
}
|
|
4956
|
+
async function copyFile(fromPath, toPath) {
|
|
4957
|
+
return new Promise((resolve, reject) => {
|
|
4958
|
+
fs__default["default"].copyFile(fromPath, toPath, (err) => {
|
|
4959
|
+
if (err) {
|
|
4960
|
+
reject(err);
|
|
4961
|
+
}
|
|
4962
|
+
else {
|
|
4963
|
+
resolve();
|
|
4964
|
+
}
|
|
4965
|
+
});
|
|
4966
|
+
});
|
|
4967
|
+
}
|
|
4968
|
+
async function removeFile(path) {
|
|
4969
|
+
return new Promise((resolve, reject) => {
|
|
4970
|
+
fs__default["default"].rm(path, (err) => {
|
|
4971
|
+
if (err) {
|
|
4972
|
+
reject(err);
|
|
4973
|
+
}
|
|
4974
|
+
else {
|
|
4975
|
+
resolve();
|
|
4976
|
+
}
|
|
4977
|
+
});
|
|
4978
|
+
});
|
|
4979
|
+
}
|
|
4980
|
+
async function moveFile(fromPath, toPath) {
|
|
4981
|
+
return new Promise((resolve, reject) => {
|
|
4982
|
+
fs__default["default"].rename(fromPath, toPath, (err) => {
|
|
4983
|
+
if (err) {
|
|
4984
|
+
reject(err);
|
|
4985
|
+
}
|
|
4986
|
+
else {
|
|
4987
|
+
resolve();
|
|
4988
|
+
}
|
|
4989
|
+
});
|
|
4990
|
+
});
|
|
4991
|
+
}
|
|
4992
|
+
async function appendFile(path, data) {
|
|
4993
|
+
return new Promise((resolve, reject) => {
|
|
4994
|
+
fs__default["default"].appendFile(path, Buffer.from(data), (err) => {
|
|
4995
|
+
if (err) {
|
|
4996
|
+
reject(err);
|
|
4997
|
+
}
|
|
4998
|
+
else {
|
|
4999
|
+
resolve();
|
|
5000
|
+
}
|
|
5001
|
+
});
|
|
5002
|
+
});
|
|
5003
|
+
}
|
|
5004
|
+
async function writeFile(path, data) {
|
|
5005
|
+
return new Promise((resolve, reject) => {
|
|
5006
|
+
fs__default["default"].writeFile(path, Buffer.from(data), (err) => {
|
|
5007
|
+
if (err) {
|
|
5008
|
+
reject(err);
|
|
5009
|
+
}
|
|
5010
|
+
else {
|
|
5011
|
+
resolve();
|
|
5012
|
+
}
|
|
5013
|
+
});
|
|
5014
|
+
});
|
|
5015
|
+
}
|
|
5016
|
+
function ensureDirectoryExists(dirPath) {
|
|
5017
|
+
if (!fs__default["default"].existsSync(dirPath)) {
|
|
5018
|
+
const parentDirPath = path__default["default"].dirname(dirPath);
|
|
5019
|
+
if (parentDirPath == dirPath) {
|
|
5020
|
+
return;
|
|
5021
|
+
}
|
|
5022
|
+
ensureDirectoryExists(parentDirPath);
|
|
5023
|
+
fs__default["default"].mkdirSync(dirPath);
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
5026
|
+
function enumFileBaseNamesInDirectory(options) {
|
|
5027
|
+
const { dirPath, prefix, fileNameFilter } = options;
|
|
5028
|
+
let fileNames = [];
|
|
5029
|
+
let resolvedDirPath = dirPath;
|
|
5030
|
+
const isRelative = dirPath.startsWith(".") || dirPath.startsWith("..");
|
|
5031
|
+
if (isRelative) {
|
|
5032
|
+
resolvedDirPath = path__default["default"].join(process.cwd(), dirPath);
|
|
5033
|
+
}
|
|
5034
|
+
if (!fs__default["default"].existsSync(resolvedDirPath)) {
|
|
5035
|
+
console.warn(`Directory '${resolvedDirPath}' not found.`);
|
|
5036
|
+
return [];
|
|
5037
|
+
}
|
|
5038
|
+
const files = fs__default["default"].readdirSync(resolvedDirPath);
|
|
5039
|
+
for (const fileName of files) {
|
|
5040
|
+
const filePathName = path__default["default"].join(resolvedDirPath, fileName);
|
|
5041
|
+
const fileStat = fs__default["default"].statSync(filePathName);
|
|
5042
|
+
if (fileStat.isDirectory()) {
|
|
5043
|
+
fileNames = fileNames.concat(enumFileBaseNamesInDirectory({
|
|
5044
|
+
dirPath: filePathName,
|
|
5045
|
+
prefix: prefix ? `${prefix}/${fileName}` : fileName,
|
|
5046
|
+
fileNameFilter,
|
|
5047
|
+
}));
|
|
5048
|
+
}
|
|
5049
|
+
else if (fileStat.isFile()) {
|
|
5050
|
+
if (fileNameFilter && !fileNameFilter(fileName)) {
|
|
5051
|
+
continue;
|
|
5052
|
+
}
|
|
5053
|
+
const baseName = path__default["default"].parse(fileName).name;
|
|
5054
|
+
if (prefix) {
|
|
5055
|
+
fileNames.push(`${prefix}/${baseName}`);
|
|
5056
|
+
}
|
|
5057
|
+
else {
|
|
5058
|
+
fileNames.push(baseName);
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
}
|
|
5062
|
+
fileNames.sort();
|
|
5063
|
+
return fileNames;
|
|
5064
|
+
}
|
|
5065
|
+
|
|
4944
5066
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
4945
5067
|
// This module is browser compatible.
|
|
4946
5068
|
/**
|
|
@@ -7373,31 +7495,6 @@ class AuthPlugin {
|
|
|
7373
7495
|
}
|
|
7374
7496
|
}
|
|
7375
7497
|
|
|
7376
|
-
async function readFile(path) {
|
|
7377
|
-
return new Promise((resolve, reject) => {
|
|
7378
|
-
fs__default["default"].readFile(path, null, (err, data) => {
|
|
7379
|
-
if (err) {
|
|
7380
|
-
reject(err);
|
|
7381
|
-
}
|
|
7382
|
-
else {
|
|
7383
|
-
resolve(data);
|
|
7384
|
-
}
|
|
7385
|
-
});
|
|
7386
|
-
});
|
|
7387
|
-
}
|
|
7388
|
-
async function appendFile(path, data) {
|
|
7389
|
-
return new Promise((resolve, reject) => {
|
|
7390
|
-
fs__default["default"].appendFile(path, Buffer.from(data), (err) => {
|
|
7391
|
-
if (err) {
|
|
7392
|
-
reject(err);
|
|
7393
|
-
}
|
|
7394
|
-
else {
|
|
7395
|
-
resolve();
|
|
7396
|
-
}
|
|
7397
|
-
});
|
|
7398
|
-
});
|
|
7399
|
-
}
|
|
7400
|
-
|
|
7401
7498
|
function getFileBaseName(pathname) {
|
|
7402
7499
|
const extName = path__default["default"].extname(pathname);
|
|
7403
7500
|
return path__default["default"].basename(pathname, extName);
|
|
@@ -7511,7 +7608,7 @@ async function handler$8(plugin, ctx, options) {
|
|
|
7511
7608
|
const fileKey = `${uuid.v1()}${extName}`;
|
|
7512
7609
|
const filePathName = path__default["default"].join(server.config.localFileStoragePath, fileKey);
|
|
7513
7610
|
const fileBuffer = await file.arrayBuffer();
|
|
7514
|
-
await
|
|
7611
|
+
await writeFile(filePathName, fileBuffer);
|
|
7515
7612
|
ctx.output = { ok: true, fileKey };
|
|
7516
7613
|
}
|
|
7517
7614
|
|
|
@@ -9706,12 +9803,16 @@ exports.ServerOperationPlugin = ServerOperationPlugin;
|
|
|
9706
9803
|
exports.SettingPlugin = SettingPlugin;
|
|
9707
9804
|
exports.StateMachinePlugin = StateMachinePlugin;
|
|
9708
9805
|
exports.WebhooksPlugin = WebhooksPlugin;
|
|
9806
|
+
exports.appendFile = appendFile;
|
|
9709
9807
|
exports.bootstrapApplicationConfig = bootstrapApplicationConfig$1;
|
|
9808
|
+
exports.copyFile = copyFile;
|
|
9710
9809
|
exports.createJwt = createJwt;
|
|
9711
9810
|
exports.decodeJwt = decodeJwt;
|
|
9712
9811
|
exports.deleteCookie = deleteCookie;
|
|
9713
9812
|
exports.detectChangedFieldsOfEntity = detectChangedFieldsOfEntity;
|
|
9813
|
+
exports.ensureDirectoryExists = ensureDirectoryExists;
|
|
9714
9814
|
exports.entityHelper = entityHelper;
|
|
9815
|
+
exports.enumFileBaseNamesInDirectory = enumFileBaseNamesInDirectory;
|
|
9715
9816
|
exports.formatDateTimeWithTimezone = formatDateTimeWithTimezone;
|
|
9716
9817
|
exports.generateJwtSecretKey = generateJwtSecretKey;
|
|
9717
9818
|
exports.generatePasswordHash = generatePasswordHash;
|
|
@@ -9725,8 +9826,12 @@ exports.isAccessAllowed = isAccessAllowed;
|
|
|
9725
9826
|
exports.licenseHelper = licenseHelper;
|
|
9726
9827
|
exports.mapDbRowToEntity = mapDbRowToEntity;
|
|
9727
9828
|
exports.metaHelper = metaHelper;
|
|
9829
|
+
exports.moveFile = moveFile;
|
|
9830
|
+
exports.readFile = readFile;
|
|
9831
|
+
exports.removeFile = removeFile;
|
|
9728
9832
|
exports.setCookie = setCookie;
|
|
9729
9833
|
exports.tryValidateLicense = tryValidateLicense;
|
|
9730
9834
|
exports.validateLicense = validateLicense;
|
|
9731
9835
|
exports.validatePassword = validatePassword;
|
|
9732
9836
|
exports.verifyJwt = verifyJwt;
|
|
9837
|
+
exports.writeFile = writeFile;
|
|
@@ -4,3 +4,11 @@ export declare function copyFile(fromPath: string, toPath: string): Promise<void
|
|
|
4
4
|
export declare function removeFile(path: string): Promise<void>;
|
|
5
5
|
export declare function moveFile(fromPath: string, toPath: string): Promise<void>;
|
|
6
6
|
export declare function appendFile(path: string, data: ArrayBuffer): Promise<void>;
|
|
7
|
+
export declare function writeFile(path: string, data: ArrayBuffer): Promise<void>;
|
|
8
|
+
export declare function ensureDirectoryExists(dirPath: string): void;
|
|
9
|
+
export type EnumFileBaseNamesOptions = {
|
|
10
|
+
dirPath: string;
|
|
11
|
+
prefix?: string;
|
|
12
|
+
fileNameFilter?: (fileName: string) => boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function enumFileBaseNamesInDirectory(options: EnumFileBaseNamesOptions): string[];
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from "./dataAccess/entityManager";
|
|
|
20
20
|
|
|
21
21
|
export * from "./utilities/accessControlUtility";
|
|
22
22
|
export * from "./utilities/entityUtility";
|
|
23
|
+
export * from "./utilities/fsUtility";
|
|
23
24
|
export * from "./utilities/jwtUtility";
|
|
24
25
|
export * from "./utilities/timeUtility";
|
|
25
26
|
export * from "./utilities/passwordUtility";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v1 as uuidv1 } from "uuid";
|
|
2
|
-
import {
|
|
2
|
+
import { writeFile } from "~/utilities/fsUtility";
|
|
3
3
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { isArray } from "lodash";
|
|
@@ -27,7 +27,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
|
|
|
27
27
|
const filePathName = path.join(server.config.localFileStoragePath, fileKey);
|
|
28
28
|
|
|
29
29
|
const fileBuffer = await file.arrayBuffer();
|
|
30
|
-
await
|
|
30
|
+
await writeFile(filePathName, fileBuffer);
|
|
31
31
|
|
|
32
32
|
ctx.output = { ok: true, fileKey };
|
|
33
33
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
2
3
|
|
|
3
4
|
export async function readFile(path: string): Promise<Buffer> {
|
|
4
5
|
return new Promise((resolve, reject) => {
|
|
@@ -59,3 +60,78 @@ export async function appendFile(path: string, data: ArrayBuffer): Promise<void>
|
|
|
59
60
|
});
|
|
60
61
|
});
|
|
61
62
|
}
|
|
63
|
+
|
|
64
|
+
export async function writeFile(path: string, data: ArrayBuffer): Promise<void> {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
fs.writeFile(path, Buffer.from(data), (err) => {
|
|
67
|
+
if (err) {
|
|
68
|
+
reject(err);
|
|
69
|
+
} else {
|
|
70
|
+
resolve();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function ensureDirectoryExists(dirPath: string) {
|
|
77
|
+
if (!fs.existsSync(dirPath)) {
|
|
78
|
+
const parentDirPath = path.dirname(dirPath);
|
|
79
|
+
if (parentDirPath == dirPath) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
ensureDirectoryExists(parentDirPath);
|
|
83
|
+
|
|
84
|
+
fs.mkdirSync(dirPath);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type EnumFileBaseNamesOptions = {
|
|
89
|
+
dirPath: string;
|
|
90
|
+
prefix?: string;
|
|
91
|
+
fileNameFilter?: (fileName: string) => boolean;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export function enumFileBaseNamesInDirectory(options: EnumFileBaseNamesOptions): string[] {
|
|
95
|
+
const { dirPath, prefix, fileNameFilter } = options;
|
|
96
|
+
let fileNames = [];
|
|
97
|
+
|
|
98
|
+
let resolvedDirPath = dirPath;
|
|
99
|
+
const isRelative = dirPath.startsWith(".") || dirPath.startsWith("..");
|
|
100
|
+
if (isRelative) {
|
|
101
|
+
resolvedDirPath = path.join(process.cwd(), dirPath);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!fs.existsSync(resolvedDirPath)) {
|
|
105
|
+
console.warn(`Directory '${resolvedDirPath}' not found.`);
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const files = fs.readdirSync(resolvedDirPath);
|
|
110
|
+
for (const fileName of files) {
|
|
111
|
+
const filePathName = path.join(resolvedDirPath, fileName);
|
|
112
|
+
const fileStat = fs.statSync(filePathName);
|
|
113
|
+
if (fileStat.isDirectory()) {
|
|
114
|
+
fileNames = fileNames.concat(
|
|
115
|
+
enumFileBaseNamesInDirectory({
|
|
116
|
+
dirPath: filePathName,
|
|
117
|
+
prefix: prefix ? `${prefix}/${fileName}` : fileName,
|
|
118
|
+
fileNameFilter,
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
} else if (fileStat.isFile()) {
|
|
122
|
+
if (fileNameFilter && !fileNameFilter(fileName)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const baseName = path.parse(fileName).name;
|
|
127
|
+
if (prefix) {
|
|
128
|
+
fileNames.push(`${prefix}/${baseName}`);
|
|
129
|
+
} else {
|
|
130
|
+
fileNames.push(baseName);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fileNames.sort();
|
|
136
|
+
return fileNames;
|
|
137
|
+
}
|