nextjs-cms 0.5.82 → 0.5.84
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/core/fields/document.d.ts +1 -0
- package/dist/core/fields/document.d.ts.map +1 -1
- package/dist/core/fields/document.js +6 -0
- package/dist/core/fields/fileField.d.ts +1 -0
- package/dist/core/fields/fileField.d.ts.map +1 -1
- package/dist/core/fields/photo.d.ts +1 -0
- package/dist/core/fields/photo.d.ts.map +1 -1
- package/dist/core/fields/photo.js +7 -0
- package/dist/core/fields/select.d.ts +1 -1
- package/dist/core/fields/tags.d.ts +33 -2
- package/dist/core/fields/tags.d.ts.map +1 -1
- package/dist/core/fields/tags.js +129 -7
- package/dist/core/fields/video.d.ts +1 -0
- package/dist/core/fields/video.d.ts.map +1 -1
- package/dist/core/fields/video.js +6 -0
- package/dist/core/sections/category.d.ts +4 -4
- package/dist/core/sections/hasItems.d.ts +4 -4
- package/dist/core/sections/section.d.ts +2 -2
- package/dist/core/sections/simple.d.ts +4 -4
- package/dist/core/submit/ItemEditSubmit.d.ts +2 -0
- package/dist/core/submit/ItemEditSubmit.d.ts.map +1 -1
- package/dist/core/submit/ItemEditSubmit.js +27 -0
- package/package.json +3 -3
|
@@ -82,6 +82,7 @@ export declare class DocumentField extends FileField<'document', Config> {
|
|
|
82
82
|
writeToFile(): Promise<void>;
|
|
83
83
|
postSubmit(folder: string): Promise<void>;
|
|
84
84
|
postSubmitRollback(): Promise<void>;
|
|
85
|
+
cleanupReplacedFile(previousValue: string, sectionName: string): Promise<void>;
|
|
85
86
|
/**
|
|
86
87
|
* Get the value of the field
|
|
87
88
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../src/core/fields/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB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Error(`${this.label}: Error deleting file from disk`);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
async cleanupReplacedFile(previousValue, sectionName) {
|
|
161
|
+
if (!previousValue)
|
|
162
|
+
return;
|
|
163
|
+
const uploadsFolder = (await getCMSConfig()).media.upload.path;
|
|
164
|
+
await fs.promises.unlink(path.join(uploadsFolder, '.documents', sectionName, previousValue));
|
|
165
|
+
}
|
|
160
166
|
/**
|
|
161
167
|
* Get the value of the field
|
|
162
168
|
*/
|
|
@@ -10,6 +10,7 @@ export declare abstract class FileField<TType extends FileType = FileType, TExtr
|
|
|
10
10
|
abstract writeToFile(): Promise<void>;
|
|
11
11
|
abstract setFileName(value: string): void;
|
|
12
12
|
abstract setFile(file: File): void;
|
|
13
|
+
abstract cleanupReplacedFile(previousValue: string, sectionName: string): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export {};
|
|
15
16
|
//# sourceMappingURL=fileField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileField.d.ts","sourceRoot":"","sources":["../../../src/core/fields/fileField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,KAAK,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAA;AAC9C,8BAAsB,SAAS,CAC3B,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,iBAAiB,SAAS,MAAM,GAAG,MAAM,CAC3C,SAAQ,KAAK,CAAC,KAAK,EAAE,iBAAiB,CAAC;IACrC,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAc;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IACrC,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IACzC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"fileField.d.ts","sourceRoot":"","sources":["../../../src/core/fields/fileField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,KAAK,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAA;AAC9C,8BAAsB,SAAS,CAC3B,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,iBAAiB,SAAS,MAAM,GAAG,MAAM,CAC3C,SAAQ,KAAK,CAAC,KAAK,EAAE,iBAAiB,CAAC;IACrC,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAc;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IACrC,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IACzC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAClC,QAAQ,CAAC,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAC1F"}
|
|
@@ -134,6 +134,7 @@ export declare class PhotoField extends FileField<'photo', Config> {
|
|
|
134
134
|
writeToFile(): Promise<void>;
|
|
135
135
|
postSubmit(folder: string): Promise<void>;
|
|
136
136
|
postSubmitRollback(): Promise<void>;
|
|
137
|
+
cleanupReplacedFile(previousValue: string, sectionName: string): Promise<void>;
|
|
137
138
|
/**
|
|
138
139
|
* Get the value of the field
|
|
139
140
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"photo.d.ts","sourceRoot":"","sources":["../../../src/core/fields/photo.ts"],"names":[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G;IACH,QAAQ,IAAI,MAAM;IAIX,WAAW,CAAC,KAAK,EAAE,MAAM;IAIvB,QAAQ,CAAC,KAAK,EAAE,GAAG;IAQ5B,OAAO,CAAC,IAAI,EAAE,IAAI;IAKlB,aAAa;IAab;;OAEG;IACG,oBAAoB;CAqJ7B;AAED,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAA;AAE9E,QAAA,MAAM,aAAa;IAnaf,yCAAyC;;;;;;QA7BzC;;;;;;;;;;;;WAYG;;;;;;;;;IAsBH;;;;;;;OAOG;;;;;;;;IAEH;;;;;;;OAOG;;;;;;;IAEH;;;OAGG;;;;;;;;;kBA4YL,CAAA;AAEF,QAAA,MAAM,sBAAsB;;;IAxaxB,yCAAyC;;;;;;QA7BzC;;;;;;;;;;;;WAYG;;;;;;;;;IAsBH;;;;;;;OAOG;;;;;;;;IAEH;;;;;;;OAOG;;;;;;;IAEH;;;OAGG;;;;;;;;;kBAkZL,CAAA;AAEF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAErE;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAAG,gBAAgB,CAmBjF"}
|
|
@@ -241,6 +241,13 @@ export class PhotoField extends FileField {
|
|
|
241
241
|
throw new Error(`${this.label}: Error deleting file from disk`);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
+
async cleanupReplacedFile(previousValue, sectionName) {
|
|
245
|
+
if (!previousValue)
|
|
246
|
+
return;
|
|
247
|
+
const uploadsFolder = (await getCMSConfig()).media.upload.path;
|
|
248
|
+
await fs.promises.unlink(path.join(uploadsFolder, '.photos', sectionName, previousValue));
|
|
249
|
+
await fs.promises.unlink(path.join(uploadsFolder, '.thumbs', sectionName, previousValue));
|
|
250
|
+
}
|
|
244
251
|
/**
|
|
245
252
|
* Get the value of the field
|
|
246
253
|
*/
|
|
@@ -346,8 +346,8 @@ declare const selectFieldConfigSchema: z.ZodIntersection<z.ZodUnion<readonly [z.
|
|
|
346
346
|
}, z.core.$strict>]>, z.ZodObject<{
|
|
347
347
|
type: z.ZodLiteral<"select">;
|
|
348
348
|
optionsType: z.ZodEnum<{
|
|
349
|
-
db: "db";
|
|
350
349
|
section: "section";
|
|
350
|
+
db: "db";
|
|
351
351
|
static: "static";
|
|
352
352
|
}>;
|
|
353
353
|
build: z.ZodFunction<z.core.$ZodFunctionArgs, z.ZodCustom<SelectField, SelectField>>;
|
|
@@ -35,8 +35,18 @@ export declare class TagsField extends Field<'tags', Config> {
|
|
|
35
35
|
};
|
|
36
36
|
readonly placeholder: string;
|
|
37
37
|
readonly sanitize: boolean;
|
|
38
|
+
private _itemIdentifier;
|
|
39
|
+
private _tags;
|
|
38
40
|
constructor(config: BaseFieldConfig<Config>);
|
|
39
41
|
getValue(): any;
|
|
42
|
+
/**
|
|
43
|
+
* When destinationDb is set, the value should not be saved to the main item table
|
|
44
|
+
*/
|
|
45
|
+
hasSqlNameAndValue(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Get the value of the field when submitting to the database
|
|
48
|
+
*/
|
|
49
|
+
getSubmitValue(): string | undefined;
|
|
40
50
|
exportForClient(): {
|
|
41
51
|
placeholder: string;
|
|
42
52
|
sanitize: boolean;
|
|
@@ -51,8 +61,29 @@ export declare class TagsField extends Field<'tags', Config> {
|
|
|
51
61
|
};
|
|
52
62
|
checkRequired(): void;
|
|
53
63
|
/**
|
|
54
|
-
*
|
|
55
|
-
|
|
64
|
+
* Build the field to be rendered in a form
|
|
65
|
+
*/
|
|
66
|
+
build(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Save tags to the destination table after the main item is saved
|
|
69
|
+
*/
|
|
70
|
+
postSubmit(itemId: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Rollback the tags from the destination table if something goes wrong
|
|
73
|
+
*/
|
|
74
|
+
postSubmitRollback(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Check the destination db config is set
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
private checkDestinationDBConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Check if destination table and columns exist
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private checkDestinationDBTableAndColumns;
|
|
85
|
+
/**
|
|
86
|
+
* Prepare and build the field for submission
|
|
56
87
|
*/
|
|
57
88
|
prepareForSubmission(): Promise<void>;
|
|
58
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../../src/core/fields/tags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,KAAK,EAAyB,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../../src/core/fields/tags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,KAAK,EAAyB,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAKhD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAGxB,QAAA,MAAM,YAAY;IACd;;;OAGG;;;;;;;;;;;IAiBH;;;;;OAKG;;kBAEL,CAAA;AAEF,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAE1C,qBAAa,SAAU,SAAQ,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;IAChD,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAc;IAC3D,SAAkB,aAAa,CAAC,EAAE;QAC9B,KAAK,EAA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AG,eAAe,CAmB/E"}
|
package/dist/core/fields/tags.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Field, baseFieldConfigSchema } from './field.js';
|
|
2
2
|
import { entityKind } from '../helpers/index.js';
|
|
3
|
+
import { MysqlTableChecker } from '../db/index.js';
|
|
4
|
+
import { db } from '../../db/client.js';
|
|
5
|
+
import { sql } from 'drizzle-orm';
|
|
3
6
|
import * as z from 'zod';
|
|
4
7
|
import { escapeHTML } from '../security/dom.js';
|
|
5
8
|
const configSchema = z.strictObject({
|
|
@@ -36,6 +39,8 @@ export class TagsField extends Field {
|
|
|
36
39
|
destinationDb;
|
|
37
40
|
placeholder;
|
|
38
41
|
sanitize;
|
|
42
|
+
_itemIdentifier;
|
|
43
|
+
_tags = [];
|
|
39
44
|
constructor(config) {
|
|
40
45
|
super(config, 'tags');
|
|
41
46
|
this.destinationDb = config.destinationDb;
|
|
@@ -45,6 +50,20 @@ export class TagsField extends Field {
|
|
|
45
50
|
getValue() {
|
|
46
51
|
return this.value;
|
|
47
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* When destinationDb is set, the value should not be saved to the main item table
|
|
55
|
+
*/
|
|
56
|
+
hasSqlNameAndValue() {
|
|
57
|
+
return this.destinationDb === undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the value of the field when submitting to the database
|
|
61
|
+
*/
|
|
62
|
+
getSubmitValue() {
|
|
63
|
+
if (!this.hasSqlNameAndValue())
|
|
64
|
+
return;
|
|
65
|
+
return this.value;
|
|
66
|
+
}
|
|
48
67
|
exportForClient() {
|
|
49
68
|
return {
|
|
50
69
|
...super.exportForClient(),
|
|
@@ -58,21 +77,124 @@ export class TagsField extends Field {
|
|
|
58
77
|
}
|
|
59
78
|
}
|
|
60
79
|
/**
|
|
61
|
-
*
|
|
62
|
-
|
|
80
|
+
* Build the field to be rendered in a form
|
|
81
|
+
*/
|
|
82
|
+
async build() {
|
|
83
|
+
if (this.destinationDb) {
|
|
84
|
+
this.checkDestinationDBConfig();
|
|
85
|
+
await this.checkDestinationDBTableAndColumns();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Save tags to the destination table after the main item is saved
|
|
90
|
+
*/
|
|
91
|
+
async postSubmit(itemId) {
|
|
92
|
+
if (!this.destinationDb)
|
|
93
|
+
return;
|
|
94
|
+
this._itemIdentifier = itemId;
|
|
95
|
+
try {
|
|
96
|
+
/**
|
|
97
|
+
* Delete the existing values
|
|
98
|
+
*/
|
|
99
|
+
await db.execute(sql `DELETE FROM \`${sql.raw(this.destinationDb.table)}\` WHERE \`${sql.raw(this.destinationDb.itemIdentifier)}\` = ${this._itemIdentifier}`);
|
|
100
|
+
/**
|
|
101
|
+
* Check if we actually have values to save
|
|
102
|
+
*/
|
|
103
|
+
if (!this._tags || this._tags.length === 0) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Prepare the sql statement
|
|
108
|
+
*/
|
|
109
|
+
const sqlChunks = [];
|
|
110
|
+
sqlChunks.push(sql `INSERT INTO \`${sql.raw(this.destinationDb.table)}\` (\`${sql.raw(this.destinationDb.selectIdentifier)}\`, \`${sql.raw(this.destinationDb.itemIdentifier)}\`) VALUES `);
|
|
111
|
+
/**
|
|
112
|
+
* Loop through the tags and add them to the sql statement values
|
|
113
|
+
*/
|
|
114
|
+
const count = this._tags.length;
|
|
115
|
+
this._tags.forEach((tag, index) => {
|
|
116
|
+
sqlChunks.push(sql `(${tag}, ${this._itemIdentifier})`);
|
|
117
|
+
if (index < count - 1) {
|
|
118
|
+
/**
|
|
119
|
+
* Add a comma to separate the values in the sql statement
|
|
120
|
+
*/
|
|
121
|
+
sqlChunks.push(sql `, `);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Join the sql chunks
|
|
126
|
+
*/
|
|
127
|
+
const finalSql = sql.join(sqlChunks);
|
|
128
|
+
/**
|
|
129
|
+
* Execute the sql statement
|
|
130
|
+
*/
|
|
131
|
+
await db.execute(finalSql);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error(error);
|
|
135
|
+
throw new Error(`${this.label}: Error saving tags to the destination table`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Rollback the tags from the destination table if something goes wrong
|
|
140
|
+
*/
|
|
141
|
+
async postSubmitRollback() {
|
|
142
|
+
if (!this.destinationDb)
|
|
143
|
+
return;
|
|
144
|
+
if (!this._itemIdentifier) {
|
|
145
|
+
throw new Error(`${this.label}: Item identifier is not set. Make sure to set the item identifier by calling postSubmit() before calling postSubmitRollback()`);
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
await db.execute(sql `DELETE FROM \`${sql.raw(this.destinationDb.table)}\` WHERE \`${sql.raw(this.destinationDb.itemIdentifier)}\` = ${this._itemIdentifier}`);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw new Error(`${this.label}: Error deleting tags from the destination table`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check the destination db config is set
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
checkDestinationDBConfig() {
|
|
159
|
+
if (this.destinationDb?.table.trim().length === 0 ||
|
|
160
|
+
this.destinationDb?.selectIdentifier.trim().length === 0 ||
|
|
161
|
+
this.destinationDb?.itemIdentifier.trim().length === 0) {
|
|
162
|
+
throw new Error(`Field ${this.label}: Destination table, select identifier and item identifier are required`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if destination table and columns exist
|
|
167
|
+
* @private
|
|
168
|
+
*/
|
|
169
|
+
async checkDestinationDBTableAndColumns() {
|
|
170
|
+
if (!this.destinationDb) {
|
|
171
|
+
throw new Error(`Field ${this.label}: Destination table, select identifier and item identifier are required`);
|
|
172
|
+
}
|
|
173
|
+
const columns = await MysqlTableChecker.getColumns(this.destinationDb.table);
|
|
174
|
+
if (!columns.includes(this.destinationDb.selectIdentifier) ||
|
|
175
|
+
!columns.includes(this.destinationDb.itemIdentifier)) {
|
|
176
|
+
throw new Error(`Field ${this.label}: Table ${this.destinationDb.table} and/or columns: ${this.destinationDb.selectIdentifier}, ${this.destinationDb.itemIdentifier} do not exist in the database!, did you forget to run update-sections?`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Prepare and build the field for submission
|
|
63
181
|
*/
|
|
64
182
|
async prepareForSubmission() {
|
|
183
|
+
if (this.destinationDb) {
|
|
184
|
+
this.checkDestinationDBConfig();
|
|
185
|
+
await this.checkDestinationDBTableAndColumns();
|
|
186
|
+
}
|
|
65
187
|
if (this.value) {
|
|
66
|
-
|
|
67
|
-
if (!Array.isArray(_tags)) {
|
|
188
|
+
this._tags = this.value.split(',');
|
|
189
|
+
if (!Array.isArray(this._tags)) {
|
|
68
190
|
throw new Error(`Field ${this.label} must be an array of tags`);
|
|
69
191
|
}
|
|
70
|
-
if (_tags.some((tag) => typeof tag !== 'string')) {
|
|
192
|
+
if (this._tags.some((tag) => typeof tag !== 'string')) {
|
|
71
193
|
throw new Error(`Field ${this.label} must contain only string tags`);
|
|
72
194
|
}
|
|
73
195
|
if (this.sanitize) {
|
|
74
|
-
_tags = _tags.map((tag) => escapeHTML(tag) || tag);
|
|
75
|
-
this.value = _tags.join(',');
|
|
196
|
+
this._tags = this._tags.map((tag) => escapeHTML(tag) || tag);
|
|
197
|
+
this.value = this._tags.join(',');
|
|
76
198
|
}
|
|
77
199
|
}
|
|
78
200
|
}
|
|
@@ -68,6 +68,7 @@ export declare class VideoField extends FileField<'video', Config> {
|
|
|
68
68
|
writeToFile(): Promise<void>;
|
|
69
69
|
postSubmit(folder: string): Promise<void>;
|
|
70
70
|
postSubmitRollback(): Promise<void>;
|
|
71
|
+
cleanupReplacedFile(previousValue: string, sectionName: string): Promise<void>;
|
|
71
72
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,CAmBjF"}
|
|
@@ -130,6 +130,12 @@ export class VideoField extends FileField {
|
|
|
130
130
|
throw new Error(`${this.label}: Error deleting file from disk`);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
+
async cleanupReplacedFile(previousValue, sectionName) {
|
|
134
|
+
if (!previousValue)
|
|
135
|
+
return;
|
|
136
|
+
const uploadsFolder = (await getCMSConfig()).media.upload.path;
|
|
137
|
+
await fs.promises.unlink(path.join(uploadsFolder, '.videos', sectionName, previousValue));
|
|
138
|
+
}
|
|
133
139
|
/**
|
|
134
140
|
* Get the value of the field
|
|
135
141
|
*/
|
|
@@ -117,9 +117,10 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
117
117
|
*/
|
|
118
118
|
allowRecursiveDelete: z.ZodOptional<z.ZodBoolean>;
|
|
119
119
|
fields: z.ZodUnion<[z.ZodArray<z.ZodCustom<FieldConfig, FieldConfig>>, z.ZodArray<z.ZodCustom<FieldGroupConfig, FieldGroupConfig>>]>;
|
|
120
|
+
readonly: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
120
121
|
name: z.ZodString;
|
|
121
122
|
order: z.ZodNumber;
|
|
122
|
-
|
|
123
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
123
124
|
db: z.ZodObject<{
|
|
124
125
|
table: z.ZodString;
|
|
125
126
|
identifier: z.ZodOptional<z.ZodCustom<FieldConfig, FieldConfig>>;
|
|
@@ -159,7 +160,6 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
159
160
|
quality: z.ZodNumber;
|
|
160
161
|
}, z.core.$strict>>;
|
|
161
162
|
}, z.core.$strict>>;
|
|
162
|
-
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
163
163
|
hooks: z.ZodOptional<z.ZodCustom<import("./section.js").Hooks, import("./section.js").Hooks>>;
|
|
164
164
|
}, z.core.$strict>;
|
|
165
165
|
export declare const categorySectionConfigSchema: z.ZodObject<{
|
|
@@ -214,9 +214,10 @@ export declare const categorySectionConfigSchema: z.ZodObject<{
|
|
|
214
214
|
* @default false
|
|
215
215
|
*/
|
|
216
216
|
allowRecursiveDelete: z.ZodOptional<z.ZodBoolean>;
|
|
217
|
+
readonly: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
217
218
|
name: z.ZodString;
|
|
218
219
|
order: z.ZodNumber;
|
|
219
|
-
|
|
220
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
220
221
|
db: z.ZodObject<{
|
|
221
222
|
table: z.ZodString;
|
|
222
223
|
identifier: z.ZodOptional<z.ZodCustom<FieldConfig, FieldConfig>>;
|
|
@@ -256,7 +257,6 @@ export declare const categorySectionConfigSchema: z.ZodObject<{
|
|
|
256
257
|
quality: z.ZodNumber;
|
|
257
258
|
}, z.core.$strict>>;
|
|
258
259
|
}, z.core.$strict>>;
|
|
259
|
-
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
260
260
|
hooks: z.ZodOptional<z.ZodCustom<import("./section.js").Hooks, import("./section.js").Hooks>>;
|
|
261
261
|
}, z.core.$strict>;
|
|
262
262
|
export type CategorySectionOptions = z.infer<typeof optionsSchema>;
|
|
@@ -368,9 +368,10 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
368
368
|
}>>;
|
|
369
369
|
generateQR: z.ZodOptional<z.ZodBoolean>;
|
|
370
370
|
fields: z.ZodUnion<[z.ZodArray<z.ZodCustom<FieldConfig, FieldConfig>>, z.ZodArray<z.ZodCustom<FieldGroupConfig, FieldGroupConfig>>]>;
|
|
371
|
+
readonly: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
371
372
|
name: z.ZodString;
|
|
372
373
|
order: z.ZodNumber;
|
|
373
|
-
|
|
374
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
374
375
|
db: z.ZodObject<{
|
|
375
376
|
table: z.ZodString;
|
|
376
377
|
identifier: z.ZodOptional<z.ZodCustom<FieldConfig, FieldConfig>>;
|
|
@@ -410,7 +411,6 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
410
411
|
quality: z.ZodNumber;
|
|
411
412
|
}, z.core.$strict>>;
|
|
412
413
|
}, z.core.$strict>>;
|
|
413
|
-
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
414
414
|
hooks: z.ZodOptional<z.ZodCustom<import("./section.js").Hooks, import("./section.js").Hooks>>;
|
|
415
415
|
}, z.core.$strict>;
|
|
416
416
|
declare const hasItemsSectionConfigSchema: z.ZodObject<{
|
|
@@ -585,9 +585,10 @@ declare const hasItemsSectionConfigSchema: z.ZodObject<{
|
|
|
585
585
|
adminGenerated?: boolean | "readonly" | undefined;
|
|
586
586
|
}>>;
|
|
587
587
|
generateQR: z.ZodOptional<z.ZodBoolean>;
|
|
588
|
+
readonly: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
588
589
|
name: z.ZodString;
|
|
589
590
|
order: z.ZodNumber;
|
|
590
|
-
|
|
591
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
591
592
|
db: z.ZodObject<{
|
|
592
593
|
table: z.ZodString;
|
|
593
594
|
identifier: z.ZodOptional<z.ZodCustom<FieldConfig, FieldConfig>>;
|
|
@@ -627,7 +628,6 @@ declare const hasItemsSectionConfigSchema: z.ZodObject<{
|
|
|
627
628
|
quality: z.ZodNumber;
|
|
628
629
|
}, z.core.$strict>>;
|
|
629
630
|
}, z.core.$strict>>;
|
|
630
|
-
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
631
631
|
hooks: z.ZodOptional<z.ZodCustom<import("./section.js").Hooks, import("./section.js").Hooks>>;
|
|
632
632
|
}, z.core.$strict>;
|
|
633
633
|
export type HasItemsSectionOptions = z.infer<typeof optionsSchema>;
|
|
@@ -62,9 +62,10 @@ export declare const baseSectionOptionsSchema: z.ZodObject<{
|
|
|
62
62
|
*/
|
|
63
63
|
export declare const baseHelperFunctionOptionsSchema: z.ZodObject<{
|
|
64
64
|
fields: z.ZodUnion<[z.ZodArray<z.ZodCustom<FieldConfig, FieldConfig>>, z.ZodArray<z.ZodCustom<FieldGroupConfig, FieldGroupConfig>>]>;
|
|
65
|
+
readonly: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
65
66
|
name: z.ZodString;
|
|
66
67
|
order: z.ZodNumber;
|
|
67
|
-
|
|
68
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<Variant, Variant>>>;
|
|
68
69
|
db: z.ZodObject<{
|
|
69
70
|
table: z.ZodString;
|
|
70
71
|
identifier: z.ZodOptional<z.ZodCustom<FieldConfig, FieldConfig>>;
|
|
@@ -104,7 +105,6 @@ export declare const baseHelperFunctionOptionsSchema: z.ZodObject<{
|
|
|
104
105
|
quality: z.ZodNumber;
|
|
105
106
|
}, z.core.$strict>>;
|
|
106
107
|
}, z.core.$strict>>;
|
|
107
|
-
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<Variant, Variant>>>;
|
|
108
108
|
hooks: z.ZodOptional<z.ZodCustom<Hooks, Hooks>>;
|
|
109
109
|
}, z.core.$strict>;
|
|
110
110
|
export declare function validateSectionConfig(config: BaseSectionOptions): void;
|
|
@@ -22,9 +22,10 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
22
22
|
table: z.ZodString;
|
|
23
23
|
}, z.core.$strict>;
|
|
24
24
|
fields: z.ZodUnion<[z.ZodArray<z.ZodCustom<FieldConfig, FieldConfig>>, z.ZodArray<z.ZodCustom<FieldGroupConfig, FieldGroupConfig>>]>;
|
|
25
|
+
readonly: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
25
26
|
name: z.ZodString;
|
|
26
27
|
order: z.ZodNumber;
|
|
27
|
-
|
|
28
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
28
29
|
icon: z.ZodOptional<z.ZodString>;
|
|
29
30
|
gallery: z.ZodOptional<z.ZodObject<{
|
|
30
31
|
db: z.ZodObject<{
|
|
@@ -41,7 +42,6 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
41
42
|
quality: z.ZodNumber;
|
|
42
43
|
}, z.core.$strict>>;
|
|
43
44
|
}, z.core.$strict>>;
|
|
44
|
-
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
45
45
|
hooks: z.ZodOptional<z.ZodCustom<import("./section.js").Hooks, import("./section.js").Hooks>>;
|
|
46
46
|
}, z.core.$strict>;
|
|
47
47
|
declare const simpleSectionConfigSchema: z.ZodObject<{
|
|
@@ -53,9 +53,10 @@ declare const simpleSectionConfigSchema: z.ZodObject<{
|
|
|
53
53
|
db: z.ZodObject<{
|
|
54
54
|
table: z.ZodString;
|
|
55
55
|
}, z.core.$strict>;
|
|
56
|
+
readonly: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
56
57
|
name: z.ZodString;
|
|
57
58
|
order: z.ZodNumber;
|
|
58
|
-
|
|
59
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
59
60
|
icon: z.ZodOptional<z.ZodString>;
|
|
60
61
|
gallery: z.ZodOptional<z.ZodObject<{
|
|
61
62
|
db: z.ZodObject<{
|
|
@@ -72,7 +73,6 @@ declare const simpleSectionConfigSchema: z.ZodObject<{
|
|
|
72
73
|
quality: z.ZodNumber;
|
|
73
74
|
}, z.core.$strict>>;
|
|
74
75
|
}, z.core.$strict>>;
|
|
75
|
-
variants: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").Variant, import("../types/index.js").Variant>>>;
|
|
76
76
|
hooks: z.ZodOptional<z.ZodCustom<import("./section.js").Hooks, import("./section.js").Hooks>>;
|
|
77
77
|
}, z.core.$strict>;
|
|
78
78
|
export type SimpleSectionOptions = z.infer<typeof optionsSchema>;
|
|
@@ -23,6 +23,7 @@ export declare class EditSubmit extends Submit {
|
|
|
23
23
|
* @override
|
|
24
24
|
*/
|
|
25
25
|
initialize(): Promise<void>;
|
|
26
|
+
submit(): Promise<true | undefined>;
|
|
26
27
|
private initializeFieldValues;
|
|
27
28
|
/**
|
|
28
29
|
* Gets the field values from the associated table declared in the section info
|
|
@@ -44,6 +45,7 @@ export declare class EditSubmit extends Submit {
|
|
|
44
45
|
* @override
|
|
45
46
|
*/
|
|
46
47
|
protected submitRollback(): Promise<void>;
|
|
48
|
+
private cleanupReplacedFiles;
|
|
47
49
|
/**
|
|
48
50
|
* Build the sql query
|
|
49
51
|
* @override
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemEditSubmit.d.ts","sourceRoot":"","sources":["../../../src/core/submit/ItemEditSubmit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAItC,OAAO,KAAK,EAAuB,KAAK,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,UAAU,EAAM,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAOtC,KAAK,eAAe,GAAG;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,qBAAa,U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ACgB,aAAa,IAAI,GAAG,GAAG,SAAS;IAmBnD;;;;OAIG;IACM,aAAa,CAAC,KAAK,EAAE,KAAK;IAmBnC;;;;OAIG;IACY,WAAW,CAAC,KAAK,EAAE,KAAK;IAQvC;;OAEG;IACM,iBAAiB;IAI1B;;;;OAIG;IACM,aAAa,CAAC,KAAK,EAAE,KAAK;CAgBtC"}
|
|
@@ -25,6 +25,13 @@ export class EditSubmit extends Submit {
|
|
|
25
25
|
*/
|
|
26
26
|
await this.initializeFieldValues();
|
|
27
27
|
}
|
|
28
|
+
async submit() {
|
|
29
|
+
const result = await super.submit();
|
|
30
|
+
if (!this._error && !this.preSubmit) {
|
|
31
|
+
await this.cleanupReplacedFiles();
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
28
35
|
async initializeFieldValues() {
|
|
29
36
|
if (this._error)
|
|
30
37
|
return;
|
|
@@ -94,6 +101,26 @@ export class EditSubmit extends Submit {
|
|
|
94
101
|
* and updating the table with the original values
|
|
95
102
|
*/
|
|
96
103
|
}
|
|
104
|
+
async cleanupReplacedFiles() {
|
|
105
|
+
if (!this._sectionInfo || !this._values)
|
|
106
|
+
return;
|
|
107
|
+
for (const field of this._sectionInfo.fields ?? []) {
|
|
108
|
+
if (!is(field, FileField))
|
|
109
|
+
continue;
|
|
110
|
+
if (!(field.name in this.sqlNamesAndValues))
|
|
111
|
+
continue;
|
|
112
|
+
const previousValue = this._values[field.name];
|
|
113
|
+
const nextValue = field.getValue();
|
|
114
|
+
if (!previousValue || previousValue === nextValue)
|
|
115
|
+
continue;
|
|
116
|
+
try {
|
|
117
|
+
await field.cleanupReplacedFile(previousValue, this._sectionInfo.name);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error(`${field.label}: Error deleting old file`, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
97
124
|
/**
|
|
98
125
|
* Build the sql query
|
|
99
126
|
* @override
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-cms",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.84",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -171,8 +171,8 @@
|
|
|
171
171
|
"tsx": "^4.20.6",
|
|
172
172
|
"typescript": "^5.9.2",
|
|
173
173
|
"@lzcms/eslint-config": "0.3.0",
|
|
174
|
-
"@lzcms/
|
|
175
|
-
"@lzcms/
|
|
174
|
+
"@lzcms/prettier-config": "0.1.0",
|
|
175
|
+
"@lzcms/tsconfig": "0.1.0"
|
|
176
176
|
},
|
|
177
177
|
"license": "MIT",
|
|
178
178
|
"keywords": [
|