@adminforth/upload 1.0.31-next.0 → 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 +30 -29
- package/index.ts +13 -13
- 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
|
@@ -25,20 +25,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
// check that lifecyle rule "adminforth-unused-cleaner" exists
|
|
27
27
|
const CLEANUP_RULE_ID = 'adminforth-unused-cleaner';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
region: this.options.s3Region,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
console.error('Unable to connect to S3. Upload will not work. Skipping setup of lifecycle rule', e);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
28
|
+
const s3 = new S3({
|
|
29
|
+
credentials: {
|
|
30
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
31
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
32
|
+
},
|
|
33
|
+
region: this.options.s3Region,
|
|
34
|
+
});
|
|
42
35
|
// check bucket exists
|
|
43
36
|
const bucketExists = s3.headBucket({ Bucket: this.options.s3Bucket });
|
|
44
37
|
if (!bucketExists) {
|
|
@@ -52,6 +45,8 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
52
45
|
}
|
|
53
46
|
catch (e) {
|
|
54
47
|
if (e.name !== 'NoSuchLifecycleConfiguration') {
|
|
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);
|
|
55
50
|
throw e;
|
|
56
51
|
}
|
|
57
52
|
else {
|
|
@@ -148,7 +143,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
148
143
|
meta: pluginFrontendOptions,
|
|
149
144
|
},
|
|
150
145
|
},
|
|
151
|
-
showIn:
|
|
146
|
+
showIn: {
|
|
147
|
+
create: true,
|
|
148
|
+
edit: true,
|
|
149
|
+
list: false,
|
|
150
|
+
show: false,
|
|
151
|
+
filter: false,
|
|
152
|
+
}
|
|
152
153
|
};
|
|
153
154
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
154
155
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
@@ -173,15 +174,15 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
173
174
|
}
|
|
174
175
|
// if showIn of path column has 'create' or 'edit' remove it
|
|
175
176
|
const pathColumn = resourceConfig.columns[pathColumnIndex];
|
|
176
|
-
if (pathColumn.showIn && (pathColumn.showIn.
|
|
177
|
-
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 });
|
|
178
179
|
}
|
|
179
180
|
virtualColumn.required = pathColumn.required;
|
|
180
181
|
virtualColumn.label = pathColumn.label;
|
|
181
182
|
virtualColumn.editingNote = pathColumn.editingNote;
|
|
182
183
|
// ** HOOKS FOR CREATE **//
|
|
183
184
|
// add beforeSave hook to save virtual column to path column
|
|
184
|
-
resourceConfig.hooks.create.beforeSave.push((
|
|
185
|
+
resourceConfig.hooks.create.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
185
186
|
if (record[virtualColumn.name]) {
|
|
186
187
|
record[pathColumnName] = record[virtualColumn.name];
|
|
187
188
|
delete record[virtualColumn.name];
|
|
@@ -189,7 +190,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
189
190
|
return { ok: true };
|
|
190
191
|
}));
|
|
191
192
|
// in afterSave hook, aremove tag adminforth-not-yet-used from the file
|
|
192
|
-
resourceConfig.hooks.create.afterSave.push((
|
|
193
|
+
resourceConfig.hooks.create.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
193
194
|
process.env.HEAVY_DEBUG && console.log('💾💾 after save ', record === null || record === void 0 ? void 0 : record.id);
|
|
194
195
|
if (record[pathColumnName]) {
|
|
195
196
|
const s3 = new S3({
|
|
@@ -213,7 +214,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
213
214
|
}));
|
|
214
215
|
// ** HOOKS FOR SHOW **//
|
|
215
216
|
// add show hook to get presigned URL
|
|
216
|
-
resourceConfig.hooks.show.afterDatasourceResponse.push((
|
|
217
|
+
resourceConfig.hooks.show.afterDatasourceResponse.push((_a) => __awaiter(this, [_a], void 0, function* ({ response }) {
|
|
217
218
|
const record = response[0];
|
|
218
219
|
if (!record) {
|
|
219
220
|
return { ok: true };
|
|
@@ -232,7 +233,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
232
233
|
}));
|
|
233
234
|
// ** HOOKS FOR LIST **//
|
|
234
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) {
|
|
235
|
-
resourceConfig.hooks.list.afterDatasourceResponse.push((
|
|
236
|
+
resourceConfig.hooks.list.afterDatasourceResponse.push((_a) => __awaiter(this, [_a], void 0, function* ({ response }) {
|
|
236
237
|
const s3 = new S3({
|
|
237
238
|
credentials: {
|
|
238
239
|
accessKeyId: this.options.s3AccessKeyId,
|
|
@@ -250,7 +251,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
250
251
|
}
|
|
251
252
|
// ** HOOKS FOR DELETE **//
|
|
252
253
|
// add delete hook which sets tag adminforth-candidate-for-cleanup to true
|
|
253
|
-
resourceConfig.hooks.delete.afterSave.push((
|
|
254
|
+
resourceConfig.hooks.delete.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
254
255
|
if (record[pathColumnName]) {
|
|
255
256
|
const s3 = new S3({
|
|
256
257
|
credentials: {
|
|
@@ -282,7 +283,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
282
283
|
}));
|
|
283
284
|
// ** HOOKS FOR EDIT **//
|
|
284
285
|
// beforeSave
|
|
285
|
-
resourceConfig.hooks.edit.beforeSave.push((
|
|
286
|
+
resourceConfig.hooks.edit.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
286
287
|
// null is when value is removed
|
|
287
288
|
if (record[virtualColumn.name] || record[virtualColumn.name] === null) {
|
|
288
289
|
record[pathColumnName] = record[virtualColumn.name];
|
|
@@ -290,7 +291,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
290
291
|
return { ok: true };
|
|
291
292
|
}));
|
|
292
293
|
// add edit postSave hook to delete old file and remove tag from new file
|
|
293
|
-
resourceConfig.hooks.edit.afterSave.push((
|
|
294
|
+
resourceConfig.hooks.edit.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ updates, oldRecord }) {
|
|
294
295
|
if (updates[virtualColumn.name] || updates[virtualColumn.name] === null) {
|
|
295
296
|
const s3 = new S3({
|
|
296
297
|
credentials: {
|
|
@@ -424,15 +425,15 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
424
425
|
server.endpoint({
|
|
425
426
|
method: 'POST',
|
|
426
427
|
path: `/plugin/${this.pluginInstanceId}/generate_images`,
|
|
427
|
-
handler: (
|
|
428
|
-
var
|
|
428
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
|
|
429
|
+
var _b, _c;
|
|
429
430
|
const { prompt } = body;
|
|
430
431
|
if (this.options.generation.provider !== 'openai-dall-e') {
|
|
431
432
|
throw new Error(`Provider ${this.options.generation.provider} is not supported`);
|
|
432
433
|
}
|
|
433
|
-
if ((
|
|
434
|
+
if ((_b = this.options.generation.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
|
|
434
435
|
// rate limit
|
|
435
|
-
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));
|
|
436
437
|
if (error) {
|
|
437
438
|
return { error: this.options.generation.rateLimit.errorMessage };
|
|
438
439
|
}
|
|
@@ -468,7 +469,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
468
469
|
server.endpoint({
|
|
469
470
|
method: 'GET',
|
|
470
471
|
path: `/plugin/${this.pluginInstanceId}/cors-proxy`,
|
|
471
|
-
handler: (
|
|
472
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ query, response }) {
|
|
472
473
|
const { url } = query;
|
|
473
474
|
const resp = yield fetch(url);
|
|
474
475
|
response.setHeader('Content-Type', resp.headers.get('Content-Type'));
|
package/index.ts
CHANGED
|
@@ -26,19 +26,14 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
26
26
|
// check that lifecyle rule "adminforth-unused-cleaner" exists
|
|
27
27
|
const CLEANUP_RULE_ID = 'adminforth-unused-cleaner';
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
s3 = new S3({
|
|
29
|
+
const s3 = new S3({
|
|
32
30
|
credentials: {
|
|
33
31
|
accessKeyId: this.options.s3AccessKeyId,
|
|
34
32
|
secretAccessKey: this.options.s3SecretAccessKey,
|
|
35
33
|
},
|
|
36
34
|
region: this.options.s3Region,
|
|
37
35
|
});
|
|
38
|
-
|
|
39
|
-
console.error('Unable to connect to S3. Upload will not work. Skipping setup of lifecycle rule', e);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
36
|
+
|
|
42
37
|
// check bucket exists
|
|
43
38
|
const bucketExists = s3.headBucket({ Bucket: this.options.s3Bucket })
|
|
44
39
|
if (!bucketExists) {
|
|
@@ -53,6 +48,8 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
53
48
|
ruleExists = lifecycleConfig.Rules.some((rule: any) => rule.ID === CLEANUP_RULE_ID);
|
|
54
49
|
} catch (e: any) {
|
|
55
50
|
if (e.name !== 'NoSuchLifecycleConfiguration') {
|
|
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);
|
|
56
53
|
throw e;
|
|
57
54
|
} else {
|
|
58
55
|
ruleExists = false;
|
|
@@ -147,11 +144,14 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
147
144
|
meta: pluginFrontendOptions,
|
|
148
145
|
},
|
|
149
146
|
},
|
|
150
|
-
showIn:
|
|
147
|
+
showIn: {
|
|
148
|
+
create: true,
|
|
149
|
+
edit: true,
|
|
150
|
+
list: false,
|
|
151
|
+
show: false,
|
|
152
|
+
filter: false,
|
|
153
|
+
}
|
|
151
154
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
155
|
|
|
156
156
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
157
157
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
@@ -180,8 +180,8 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
180
180
|
|
|
181
181
|
// if showIn of path column has 'create' or 'edit' remove it
|
|
182
182
|
const pathColumn = resourceConfig.columns[pathColumnIndex];
|
|
183
|
-
if (pathColumn.showIn && (pathColumn.showIn.
|
|
184
|
-
pathColumn.showIn = pathColumn.showIn
|
|
183
|
+
if (pathColumn.showIn && (pathColumn.showIn.create || pathColumn.showIn.edit)) {
|
|
184
|
+
pathColumn.showIn = { ...pathColumn.showIn, create: false, edit: false };
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
virtualColumn.required = pathColumn.required;
|
package/package.json
CHANGED
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/upload",
|
|
3
|
-
"version": "1.
|
|
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
|