@kne/fastify-file-manager 1.0.0 → 1.0.1
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.
|
@@ -16,7 +16,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
16
16
|
await fs.writeFile(filepath, buffer);
|
|
17
17
|
return await models.fileRecord.create({
|
|
18
18
|
filename,
|
|
19
|
-
namespace,
|
|
19
|
+
namespace: namespace || options.namespace,
|
|
20
20
|
encoding,
|
|
21
21
|
mimetype,
|
|
22
22
|
hash: digest,
|
|
@@ -26,7 +26,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
26
26
|
|
|
27
27
|
const getFileUrl = async ({ id, namespace }) => {
|
|
28
28
|
const file = await models.fileRecord.findByPk(id, {
|
|
29
|
-
where: { namespace }
|
|
29
|
+
where: { namespace: namespace || options.namespace }
|
|
30
30
|
});
|
|
31
31
|
if (!file) {
|
|
32
32
|
throw new Error('文件不存在');
|
|
@@ -37,7 +37,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
37
37
|
|
|
38
38
|
const getFileInfo = async ({ id, namespace }) => {
|
|
39
39
|
const file = await models.fileRecord.findByPk(id, {
|
|
40
|
-
where: { namespace }
|
|
40
|
+
where: { namespace: namespace || options.namespace }
|
|
41
41
|
});
|
|
42
42
|
if (!file) {
|
|
43
43
|
throw new Error('文件不存在');
|
|
@@ -49,7 +49,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const getFileList = async ({ filter, namespace, currentPage, perPage }) => {
|
|
52
|
-
const queryFilter = { namespace };
|
|
52
|
+
const queryFilter = { namespace: namespace || options.namespace };
|
|
53
53
|
const { count, rows } = await models.fileRecord.findAndCountAll({
|
|
54
54
|
where: queryFilter,
|
|
55
55
|
offset: currentPage * (currentPage - 1),
|
|
@@ -63,7 +63,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
63
63
|
|
|
64
64
|
const deleteFile = async ({ id, namespace }) => {
|
|
65
65
|
const file = await models.fileRecord.findByPk(id, {
|
|
66
|
-
where: { namespace }
|
|
66
|
+
where: { namespace: namespace || options.namespace }
|
|
67
67
|
});
|
|
68
68
|
if (!file) {
|
|
69
69
|
throw new Error('文件不存在');
|