@adminforth/upload 1.0.31-next.1 → 1.1.0
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/.woodpecker/buildRelease.sh +13 -0
- package/.woodpecker/buildSlackNotify.sh +44 -0
- package/.woodpecker/release.yml +42 -0
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/build.log +15 -0
- package/custom/imageGenerator.vue +2 -1
- package/custom/tsconfig.json +19 -0
- package/custom/uploader.vue +9 -7
- package/dist/custom/imageGenerator.vue +2 -1
- package/dist/custom/tsconfig.json +19 -0
- package/dist/custom/uploader.vue +9 -7
- package/dist/index.js +23 -18
- package/index.ts +11 -9
- package/package.json +38 -6
- package/ChangeLog.md +0 -17
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
#!/bin/bash
|
|
3
|
+
|
|
4
|
+
# write npm run output both to console and to build.log
|
|
5
|
+
npm run build 2>&1 | tee build.log
|
|
6
|
+
build_status=${PIPESTATUS[0]}
|
|
7
|
+
|
|
8
|
+
# if exist status from the npm run build is not 0
|
|
9
|
+
# then exit with the status code from the npm run build
|
|
10
|
+
if [ $build_status -ne 0 ]; then
|
|
11
|
+
echo "Build failed. Exiting with status code $build_status"
|
|
12
|
+
exit $build_status
|
|
13
|
+
fi
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
set -x
|
|
4
|
+
|
|
5
|
+
COMMIT_SHORT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if [ "$CI_STEP_STATUS" = "success" ]; then
|
|
9
|
+
MESSAGE="Did a build without issues on \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\`. Commit: _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
|
|
10
|
+
|
|
11
|
+
curl -s -X POST -H "Content-Type: application/json" -d '{
|
|
12
|
+
"username": "'"$CI_COMMIT_AUTHOR"'",
|
|
13
|
+
"icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
|
|
14
|
+
"attachments": [
|
|
15
|
+
{
|
|
16
|
+
"mrkdwn_in": ["text", "pretext"],
|
|
17
|
+
"color": "#36a64f",
|
|
18
|
+
"text": "'"$MESSAGE"'"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}' "$DEVELOPERS_SLACK_WEBHOOK"
|
|
22
|
+
exit 0
|
|
23
|
+
fi
|
|
24
|
+
export BUILD_LOG=$(cat ./build.log)
|
|
25
|
+
|
|
26
|
+
BUILD_LOG=$(echo $BUILD_LOG | sed 's/"/\\"/g')
|
|
27
|
+
|
|
28
|
+
MESSAGE="Broke \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\` with commit _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
|
|
29
|
+
CODE_BLOCK="\`\`\`$BUILD_LOG\n\`\`\`"
|
|
30
|
+
|
|
31
|
+
echo "Sending slack message to developers $MESSAGE"
|
|
32
|
+
# Send the message
|
|
33
|
+
curl -sS -X POST -H "Content-Type: application/json" -d '{
|
|
34
|
+
"username": "'"$CI_COMMIT_AUTHOR"'",
|
|
35
|
+
"icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
|
|
36
|
+
"attachments": [
|
|
37
|
+
{
|
|
38
|
+
"mrkdwn_in": ["text", "pretext"],
|
|
39
|
+
"color": "#8A1C12",
|
|
40
|
+
"text": "'"$CODE_BLOCK"'",
|
|
41
|
+
"pretext": "'"$MESSAGE"'"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}' "$DEVELOPERS_SLACK_WEBHOOK" 2>&1
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
clone:
|
|
2
|
+
git:
|
|
3
|
+
image: woodpeckerci/plugin-git
|
|
4
|
+
settings:
|
|
5
|
+
partial: false
|
|
6
|
+
depth: 5
|
|
7
|
+
|
|
8
|
+
steps:
|
|
9
|
+
init-secrets:
|
|
10
|
+
when:
|
|
11
|
+
- event: push
|
|
12
|
+
image: infisical/cli
|
|
13
|
+
environment:
|
|
14
|
+
INFISICAL_TOKEN:
|
|
15
|
+
from_secret: VAULT_TOKEN
|
|
16
|
+
commands:
|
|
17
|
+
- infisical export --domain https://vault.devforth.io/api --format=dotenv-export --env="prod" > /woodpecker/deploy.vault.env
|
|
18
|
+
secrets:
|
|
19
|
+
- VAULT_TOKEN
|
|
20
|
+
|
|
21
|
+
release:
|
|
22
|
+
image: node:20
|
|
23
|
+
when:
|
|
24
|
+
- event: push
|
|
25
|
+
commands:
|
|
26
|
+
- apt update && apt install -y rsync
|
|
27
|
+
- export $(cat /woodpecker/deploy.vault.env | xargs)
|
|
28
|
+
- npm clean-install
|
|
29
|
+
- /bin/bash ./.woodpecker/buildRelease.sh
|
|
30
|
+
- npm audit signatures
|
|
31
|
+
- npx semantic-release
|
|
32
|
+
|
|
33
|
+
slack-on-failure:
|
|
34
|
+
when:
|
|
35
|
+
- event: push
|
|
36
|
+
status: [failure, success]
|
|
37
|
+
- event: push
|
|
38
|
+
image: curlimages/curl
|
|
39
|
+
commands:
|
|
40
|
+
- export $(cat /woodpecker/deploy.vault.env | xargs)
|
|
41
|
+
- /bin/sh ./.woodpecker/buildSlackNotify.sh
|
|
42
|
+
|
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Devforth.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build.log
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
> @adminforth/upload@1.0.0 build
|
|
3
|
+
> tsc && rsync -av --exclude 'node_modules' custom dist/
|
|
4
|
+
|
|
5
|
+
sending incremental file list
|
|
6
|
+
custom/
|
|
7
|
+
custom/imageGenerator.vue
|
|
8
|
+
custom/package-lock.json
|
|
9
|
+
custom/package.json
|
|
10
|
+
custom/preview.vue
|
|
11
|
+
custom/tsconfig.json
|
|
12
|
+
custom/uploader.vue
|
|
13
|
+
|
|
14
|
+
sent 37,773 bytes received 134 bytes 75,814.00 bytes/sec
|
|
15
|
+
total size is 37,291 speedup is 0.98
|
|
@@ -107,6 +107,7 @@ import { ref, onMounted, nextTick } from 'vue'
|
|
|
107
107
|
import { Carousel } from 'flowbite';
|
|
108
108
|
import { callAdminForthApi } from '@/utils';
|
|
109
109
|
import { useI18n } from 'vue-i18n';
|
|
110
|
+
import adminforth from '@/adminforth';
|
|
110
111
|
|
|
111
112
|
const { t: $t } = useI18n();
|
|
112
113
|
|
|
@@ -185,7 +186,7 @@ async function generateImages() {
|
|
|
185
186
|
});
|
|
186
187
|
|
|
187
188
|
if (resp.error) {
|
|
188
|
-
|
|
189
|
+
adminforth.alert({
|
|
189
190
|
message: $t('Error: {error}', { error: JSON.stringify(resp.error) }),
|
|
190
191
|
variant: 'danger',
|
|
191
192
|
timeout: 15,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".", // This should point to your project root
|
|
4
|
+
"paths": {
|
|
5
|
+
"@/*": [
|
|
6
|
+
// "node_modules/adminforth/dist/spa/src/*"
|
|
7
|
+
"../../../spa/src/*"
|
|
8
|
+
],
|
|
9
|
+
"*": [
|
|
10
|
+
// "node_modules/adminforth/dist/spa/node_modules/*"
|
|
11
|
+
"../../../spa/node_modules/*"
|
|
12
|
+
],
|
|
13
|
+
"@@/*": [
|
|
14
|
+
// "node_modules/adminforth/dist/spa/src/*"
|
|
15
|
+
"."
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/custom/uploader.vue
CHANGED
|
@@ -65,19 +65,21 @@
|
|
|
65
65
|
|
|
66
66
|
</template>
|
|
67
67
|
|
|
68
|
-
<script setup>
|
|
68
|
+
<script setup lang="ts">
|
|
69
69
|
import { computed, ref, onMounted, watch } from 'vue'
|
|
70
70
|
import { callAdminForthApi } from '@/utils'
|
|
71
71
|
import { IconMagic } from '@iconify-prerendered/vue-mdi';
|
|
72
72
|
import { useI18n } from 'vue-i18n';
|
|
73
73
|
import { useRoute } from 'vue-router';
|
|
74
74
|
|
|
75
|
+
|
|
75
76
|
const route = useRoute();
|
|
76
77
|
const { t } = useI18n();
|
|
77
78
|
|
|
78
79
|
const inputId = computed(() => `dropzone-file-${props.meta.pluginInstanceId}`);
|
|
79
80
|
|
|
80
81
|
import ImageGenerator from '@@/plugins/UploadPlugin/imageGenerator.vue';
|
|
82
|
+
import adminforth from '@/adminforth';
|
|
81
83
|
|
|
82
84
|
|
|
83
85
|
const props = defineProps({
|
|
@@ -194,7 +196,7 @@ const onFileChange = async (e) => {
|
|
|
194
196
|
// validate file extension
|
|
195
197
|
const allowedExtensions = props.meta.allowedExtensions || []
|
|
196
198
|
if (allowedExtensions.length > 0 && !allowedExtensions.includes(extension)) {
|
|
197
|
-
|
|
199
|
+
adminforth.alert({
|
|
198
200
|
message: t('Sorry but the file type {extension} is not allowed. Please upload a file with one of the following extensions: {allowedExtensionsLabel}', {
|
|
199
201
|
extension,
|
|
200
202
|
allowedExtensionsLabel: allowedExtensionsLabel.value,
|
|
@@ -206,7 +208,7 @@ const onFileChange = async (e) => {
|
|
|
206
208
|
|
|
207
209
|
// validate file size
|
|
208
210
|
if (props.meta.maxFileSize && size > props.meta.maxFileSize) {
|
|
209
|
-
|
|
211
|
+
adminforth.alert({
|
|
210
212
|
message: t('Sorry but the file size {size} is too large. Please upload a file with a maximum size of {maxFileSize}', {
|
|
211
213
|
size: humanifySize(size),
|
|
212
214
|
maxFileSize: humanifySize(props.meta.maxFileSize),
|
|
@@ -240,7 +242,7 @@ const onFileChange = async (e) => {
|
|
|
240
242
|
});
|
|
241
243
|
|
|
242
244
|
if (error) {
|
|
243
|
-
|
|
245
|
+
adminforth.alert({
|
|
244
246
|
message: t('File was not uploaded because of error: {error}', { error }),
|
|
245
247
|
variant: 'danger'
|
|
246
248
|
});
|
|
@@ -268,8 +270,8 @@ const onFileChange = async (e) => {
|
|
|
268
270
|
xhr.send(file);
|
|
269
271
|
});
|
|
270
272
|
if (!success) {
|
|
271
|
-
|
|
272
|
-
messageHtml: `<div>${
|
|
273
|
+
adminforth.alert({
|
|
274
|
+
messageHtml: `<div>${t('Sorry but the file was not uploaded because of S3 Request Error:')}</div>
|
|
273
275
|
<pre style="white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; max-width: 100%;">${
|
|
274
276
|
xhr.responseText.replace(/</g, '<').replace(/>/g, '>')
|
|
275
277
|
}</pre>`,
|
|
@@ -285,7 +287,7 @@ const onFileChange = async (e) => {
|
|
|
285
287
|
emit('update:value', s3Path);
|
|
286
288
|
} catch (error) {
|
|
287
289
|
console.error('Error uploading file:', error);
|
|
288
|
-
|
|
290
|
+
adminforth.alert({
|
|
289
291
|
message: t('Sorry but the file was not be uploaded. Please try again: {error}', { error: error.message }),
|
|
290
292
|
variant: 'danger'
|
|
291
293
|
});
|
|
@@ -107,6 +107,7 @@ import { ref, onMounted, nextTick } from 'vue'
|
|
|
107
107
|
import { Carousel } from 'flowbite';
|
|
108
108
|
import { callAdminForthApi } from '@/utils';
|
|
109
109
|
import { useI18n } from 'vue-i18n';
|
|
110
|
+
import adminforth from '@/adminforth';
|
|
110
111
|
|
|
111
112
|
const { t: $t } = useI18n();
|
|
112
113
|
|
|
@@ -185,7 +186,7 @@ async function generateImages() {
|
|
|
185
186
|
});
|
|
186
187
|
|
|
187
188
|
if (resp.error) {
|
|
188
|
-
|
|
189
|
+
adminforth.alert({
|
|
189
190
|
message: $t('Error: {error}', { error: JSON.stringify(resp.error) }),
|
|
190
191
|
variant: 'danger',
|
|
191
192
|
timeout: 15,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".", // This should point to your project root
|
|
4
|
+
"paths": {
|
|
5
|
+
"@/*": [
|
|
6
|
+
// "node_modules/adminforth/dist/spa/src/*"
|
|
7
|
+
"../../../spa/src/*"
|
|
8
|
+
],
|
|
9
|
+
"*": [
|
|
10
|
+
// "node_modules/adminforth/dist/spa/node_modules/*"
|
|
11
|
+
"../../../spa/node_modules/*"
|
|
12
|
+
],
|
|
13
|
+
"@@/*": [
|
|
14
|
+
// "node_modules/adminforth/dist/spa/src/*"
|
|
15
|
+
"."
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/dist/custom/uploader.vue
CHANGED
|
@@ -65,19 +65,21 @@
|
|
|
65
65
|
|
|
66
66
|
</template>
|
|
67
67
|
|
|
68
|
-
<script setup>
|
|
68
|
+
<script setup lang="ts">
|
|
69
69
|
import { computed, ref, onMounted, watch } from 'vue'
|
|
70
70
|
import { callAdminForthApi } from '@/utils'
|
|
71
71
|
import { IconMagic } from '@iconify-prerendered/vue-mdi';
|
|
72
72
|
import { useI18n } from 'vue-i18n';
|
|
73
73
|
import { useRoute } from 'vue-router';
|
|
74
74
|
|
|
75
|
+
|
|
75
76
|
const route = useRoute();
|
|
76
77
|
const { t } = useI18n();
|
|
77
78
|
|
|
78
79
|
const inputId = computed(() => `dropzone-file-${props.meta.pluginInstanceId}`);
|
|
79
80
|
|
|
80
81
|
import ImageGenerator from '@@/plugins/UploadPlugin/imageGenerator.vue';
|
|
82
|
+
import adminforth from '@/adminforth';
|
|
81
83
|
|
|
82
84
|
|
|
83
85
|
const props = defineProps({
|
|
@@ -194,7 +196,7 @@ const onFileChange = async (e) => {
|
|
|
194
196
|
// validate file extension
|
|
195
197
|
const allowedExtensions = props.meta.allowedExtensions || []
|
|
196
198
|
if (allowedExtensions.length > 0 && !allowedExtensions.includes(extension)) {
|
|
197
|
-
|
|
199
|
+
adminforth.alert({
|
|
198
200
|
message: t('Sorry but the file type {extension} is not allowed. Please upload a file with one of the following extensions: {allowedExtensionsLabel}', {
|
|
199
201
|
extension,
|
|
200
202
|
allowedExtensionsLabel: allowedExtensionsLabel.value,
|
|
@@ -206,7 +208,7 @@ const onFileChange = async (e) => {
|
|
|
206
208
|
|
|
207
209
|
// validate file size
|
|
208
210
|
if (props.meta.maxFileSize && size > props.meta.maxFileSize) {
|
|
209
|
-
|
|
211
|
+
adminforth.alert({
|
|
210
212
|
message: t('Sorry but the file size {size} is too large. Please upload a file with a maximum size of {maxFileSize}', {
|
|
211
213
|
size: humanifySize(size),
|
|
212
214
|
maxFileSize: humanifySize(props.meta.maxFileSize),
|
|
@@ -240,7 +242,7 @@ const onFileChange = async (e) => {
|
|
|
240
242
|
});
|
|
241
243
|
|
|
242
244
|
if (error) {
|
|
243
|
-
|
|
245
|
+
adminforth.alert({
|
|
244
246
|
message: t('File was not uploaded because of error: {error}', { error }),
|
|
245
247
|
variant: 'danger'
|
|
246
248
|
});
|
|
@@ -268,8 +270,8 @@ const onFileChange = async (e) => {
|
|
|
268
270
|
xhr.send(file);
|
|
269
271
|
});
|
|
270
272
|
if (!success) {
|
|
271
|
-
|
|
272
|
-
messageHtml: `<div>${
|
|
273
|
+
adminforth.alert({
|
|
274
|
+
messageHtml: `<div>${t('Sorry but the file was not uploaded because of S3 Request Error:')}</div>
|
|
273
275
|
<pre style="white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; max-width: 100%;">${
|
|
274
276
|
xhr.responseText.replace(/</g, '<').replace(/>/g, '>')
|
|
275
277
|
}</pre>`,
|
|
@@ -285,7 +287,7 @@ const onFileChange = async (e) => {
|
|
|
285
287
|
emit('update:value', s3Path);
|
|
286
288
|
} catch (error) {
|
|
287
289
|
console.error('Error uploading file:', error);
|
|
288
|
-
|
|
290
|
+
adminforth.alert({
|
|
289
291
|
message: t('Sorry but the file was not be uploaded. Please try again: {error}', { error: error.message }),
|
|
290
292
|
variant: 'danger'
|
|
291
293
|
});
|
package/dist/index.js
CHANGED
|
@@ -45,9 +45,8 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
45
45
|
}
|
|
46
46
|
catch (e) {
|
|
47
47
|
if (e.name !== 'NoSuchLifecycleConfiguration') {
|
|
48
|
-
console.error(
|
|
49
|
-
|
|
50
|
-
getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${this.options.s3Region}. Exception:`, e);
|
|
48
|
+
console.error(`⛔ Error checking lifecycle configuration, please check keys have permissions to
|
|
49
|
+
getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${this.options.s3Region}. Exception:`, e);
|
|
51
50
|
throw e;
|
|
52
51
|
}
|
|
53
52
|
else {
|
|
@@ -144,7 +143,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
144
143
|
meta: pluginFrontendOptions,
|
|
145
144
|
},
|
|
146
145
|
},
|
|
147
|
-
showIn:
|
|
146
|
+
showIn: {
|
|
147
|
+
create: true,
|
|
148
|
+
edit: true,
|
|
149
|
+
list: false,
|
|
150
|
+
show: false,
|
|
151
|
+
filter: false,
|
|
152
|
+
}
|
|
148
153
|
};
|
|
149
154
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
150
155
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
@@ -169,15 +174,15 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
169
174
|
}
|
|
170
175
|
// if showIn of path column has 'create' or 'edit' remove it
|
|
171
176
|
const pathColumn = resourceConfig.columns[pathColumnIndex];
|
|
172
|
-
if (pathColumn.showIn && (pathColumn.showIn.
|
|
173
|
-
pathColumn.showIn = pathColumn.showIn
|
|
177
|
+
if (pathColumn.showIn && (pathColumn.showIn.create || pathColumn.showIn.edit)) {
|
|
178
|
+
pathColumn.showIn = Object.assign(Object.assign({}, pathColumn.showIn), { create: false, edit: false });
|
|
174
179
|
}
|
|
175
180
|
virtualColumn.required = pathColumn.required;
|
|
176
181
|
virtualColumn.label = pathColumn.label;
|
|
177
182
|
virtualColumn.editingNote = pathColumn.editingNote;
|
|
178
183
|
// ** HOOKS FOR CREATE **//
|
|
179
184
|
// add beforeSave hook to save virtual column to path column
|
|
180
|
-
resourceConfig.hooks.create.beforeSave.push((
|
|
185
|
+
resourceConfig.hooks.create.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
181
186
|
if (record[virtualColumn.name]) {
|
|
182
187
|
record[pathColumnName] = record[virtualColumn.name];
|
|
183
188
|
delete record[virtualColumn.name];
|
|
@@ -185,7 +190,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
185
190
|
return { ok: true };
|
|
186
191
|
}));
|
|
187
192
|
// in afterSave hook, aremove tag adminforth-not-yet-used from the file
|
|
188
|
-
resourceConfig.hooks.create.afterSave.push((
|
|
193
|
+
resourceConfig.hooks.create.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
189
194
|
process.env.HEAVY_DEBUG && console.log('💾💾 after save ', record === null || record === void 0 ? void 0 : record.id);
|
|
190
195
|
if (record[pathColumnName]) {
|
|
191
196
|
const s3 = new S3({
|
|
@@ -209,7 +214,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
209
214
|
}));
|
|
210
215
|
// ** HOOKS FOR SHOW **//
|
|
211
216
|
// add show hook to get presigned URL
|
|
212
|
-
resourceConfig.hooks.show.afterDatasourceResponse.push((
|
|
217
|
+
resourceConfig.hooks.show.afterDatasourceResponse.push((_a) => __awaiter(this, [_a], void 0, function* ({ response }) {
|
|
213
218
|
const record = response[0];
|
|
214
219
|
if (!record) {
|
|
215
220
|
return { ok: true };
|
|
@@ -228,7 +233,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
228
233
|
}));
|
|
229
234
|
// ** HOOKS FOR LIST **//
|
|
230
235
|
if (((_j = this.options.preview) === null || _j === void 0 ? void 0 : _j.showInList) || ((_k = this.options.preview) === null || _k === void 0 ? void 0 : _k.showInList) === undefined) {
|
|
231
|
-
resourceConfig.hooks.list.afterDatasourceResponse.push((
|
|
236
|
+
resourceConfig.hooks.list.afterDatasourceResponse.push((_a) => __awaiter(this, [_a], void 0, function* ({ response }) {
|
|
232
237
|
const s3 = new S3({
|
|
233
238
|
credentials: {
|
|
234
239
|
accessKeyId: this.options.s3AccessKeyId,
|
|
@@ -246,7 +251,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
246
251
|
}
|
|
247
252
|
// ** HOOKS FOR DELETE **//
|
|
248
253
|
// add delete hook which sets tag adminforth-candidate-for-cleanup to true
|
|
249
|
-
resourceConfig.hooks.delete.afterSave.push((
|
|
254
|
+
resourceConfig.hooks.delete.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
250
255
|
if (record[pathColumnName]) {
|
|
251
256
|
const s3 = new S3({
|
|
252
257
|
credentials: {
|
|
@@ -278,7 +283,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
278
283
|
}));
|
|
279
284
|
// ** HOOKS FOR EDIT **//
|
|
280
285
|
// beforeSave
|
|
281
|
-
resourceConfig.hooks.edit.beforeSave.push((
|
|
286
|
+
resourceConfig.hooks.edit.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
282
287
|
// null is when value is removed
|
|
283
288
|
if (record[virtualColumn.name] || record[virtualColumn.name] === null) {
|
|
284
289
|
record[pathColumnName] = record[virtualColumn.name];
|
|
@@ -286,7 +291,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
286
291
|
return { ok: true };
|
|
287
292
|
}));
|
|
288
293
|
// add edit postSave hook to delete old file and remove tag from new file
|
|
289
|
-
resourceConfig.hooks.edit.afterSave.push((
|
|
294
|
+
resourceConfig.hooks.edit.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ updates, oldRecord }) {
|
|
290
295
|
if (updates[virtualColumn.name] || updates[virtualColumn.name] === null) {
|
|
291
296
|
const s3 = new S3({
|
|
292
297
|
credentials: {
|
|
@@ -420,15 +425,15 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
420
425
|
server.endpoint({
|
|
421
426
|
method: 'POST',
|
|
422
427
|
path: `/plugin/${this.pluginInstanceId}/generate_images`,
|
|
423
|
-
handler: (
|
|
424
|
-
var
|
|
428
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
|
|
429
|
+
var _b, _c;
|
|
425
430
|
const { prompt } = body;
|
|
426
431
|
if (this.options.generation.provider !== 'openai-dall-e') {
|
|
427
432
|
throw new Error(`Provider ${this.options.generation.provider} is not supported`);
|
|
428
433
|
}
|
|
429
|
-
if ((
|
|
434
|
+
if ((_b = this.options.generation.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
|
|
430
435
|
// rate limit
|
|
431
|
-
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (
|
|
436
|
+
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_c = this.options.generation.rateLimit) === null || _c === void 0 ? void 0 : _c.limit, this.adminforth.auth.getClientIp(headers));
|
|
432
437
|
if (error) {
|
|
433
438
|
return { error: this.options.generation.rateLimit.errorMessage };
|
|
434
439
|
}
|
|
@@ -464,7 +469,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
464
469
|
server.endpoint({
|
|
465
470
|
method: 'GET',
|
|
466
471
|
path: `/plugin/${this.pluginInstanceId}/cors-proxy`,
|
|
467
|
-
handler: (
|
|
472
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ query, response }) {
|
|
468
473
|
const { url } = query;
|
|
469
474
|
const resp = yield fetch(url);
|
|
470
475
|
response.setHeader('Content-Type', resp.headers.get('Content-Type'));
|
package/index.ts
CHANGED
|
@@ -48,9 +48,8 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
48
48
|
ruleExists = lifecycleConfig.Rules.some((rule: any) => rule.ID === CLEANUP_RULE_ID);
|
|
49
49
|
} catch (e: any) {
|
|
50
50
|
if (e.name !== 'NoSuchLifecycleConfiguration') {
|
|
51
|
-
console.error(
|
|
52
|
-
|
|
53
|
-
getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${this.options.s3Region}. Exception:`, e);
|
|
51
|
+
console.error(`⛔ Error checking lifecycle configuration, please check keys have permissions to
|
|
52
|
+
getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${this.options.s3Region}. Exception:`, e);
|
|
54
53
|
throw e;
|
|
55
54
|
} else {
|
|
56
55
|
ruleExists = false;
|
|
@@ -145,11 +144,14 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
145
144
|
meta: pluginFrontendOptions,
|
|
146
145
|
},
|
|
147
146
|
},
|
|
148
|
-
showIn:
|
|
147
|
+
showIn: {
|
|
148
|
+
create: true,
|
|
149
|
+
edit: true,
|
|
150
|
+
list: false,
|
|
151
|
+
show: false,
|
|
152
|
+
filter: false,
|
|
153
|
+
}
|
|
149
154
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
155
|
|
|
154
156
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
155
157
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
@@ -178,8 +180,8 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
178
180
|
|
|
179
181
|
// if showIn of path column has 'create' or 'edit' remove it
|
|
180
182
|
const pathColumn = resourceConfig.columns[pathColumnIndex];
|
|
181
|
-
if (pathColumn.showIn && (pathColumn.showIn.
|
|
182
|
-
pathColumn.showIn = pathColumn.showIn
|
|
183
|
+
if (pathColumn.showIn && (pathColumn.showIn.create || pathColumn.showIn.edit)) {
|
|
184
|
+
pathColumn.showIn = { ...pathColumn.showIn, create: false, edit: false };
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
virtualColumn.required = pathColumn.required;
|
package/package.json
CHANGED
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/upload",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Plugin for uploading files for adminforth",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/devforth/adminforth-upload.git"
|
|
10
|
+
},
|
|
7
11
|
"scripts": {
|
|
8
|
-
"rollout": "tsc && rsync -av --exclude 'node_modules' custom dist/ && npm version patch && npm publish --access public",
|
|
9
12
|
"prepare": "npm link adminforth",
|
|
10
|
-
"
|
|
11
|
-
"build": "tsc"
|
|
13
|
+
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/"
|
|
12
14
|
},
|
|
13
15
|
"type": "module",
|
|
14
|
-
"author": "",
|
|
16
|
+
"author": "devforth",
|
|
15
17
|
"license": "ISC",
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"@aws-sdk/client-s3": "^3.629.0",
|
|
18
20
|
"@aws-sdk/s3-request-presigner": "^3.629.0"
|
|
21
|
+
},
|
|
22
|
+
"release": {
|
|
23
|
+
"plugins": [
|
|
24
|
+
"@semantic-release/commit-analyzer",
|
|
25
|
+
"@semantic-release/release-notes-generator",
|
|
26
|
+
"@semantic-release/npm",
|
|
27
|
+
"@semantic-release/github",
|
|
28
|
+
[
|
|
29
|
+
"semantic-release-slack-bot",
|
|
30
|
+
{
|
|
31
|
+
"notifyOnSuccess": true,
|
|
32
|
+
"notifyOnFail": true,
|
|
33
|
+
"slackIcon": ":package:",
|
|
34
|
+
"markdownReleaseNotes": true
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
],
|
|
38
|
+
"branches": [
|
|
39
|
+
"main",
|
|
40
|
+
{
|
|
41
|
+
"name": "next",
|
|
42
|
+
"prerelease": true
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^22.10.7",
|
|
48
|
+
"semantic-release": "^24.2.1",
|
|
49
|
+
"semantic-release-slack-bot": "^4.0.2",
|
|
50
|
+
"typescript": "^5.7.3"
|
|
19
51
|
}
|
|
20
52
|
}
|
package/ChangeLog.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
## [1.0.30] - 2024-12-26
|
|
3
|
-
|
|
4
|
-
### Improved
|
|
5
|
-
|
|
6
|
-
- Add 'record' param for s3Path callback in edit mode
|
|
7
|
-
|
|
8
|
-
## [1.0.24] - 2023-12-24
|
|
9
|
-
|
|
10
|
-
### Fixed
|
|
11
|
-
- Add translation
|
|
12
|
-
|
|
13
|
-
## [1.0.23] - 2023-10-07
|
|
14
|
-
|
|
15
|
-
### Fixed
|
|
16
|
-
- preview maxWidth to limit max width of image
|
|
17
|
-
- Added accept attribute to input
|