picgo-plugin-cloudflare-imgbed 0.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.
package/License ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 - present konrad
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/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ## picgo-plugin-picgo-plugin-cloudflare-imgbed
2
+
3
+ PicGo Uploader For MarSeventh/CloudFlare-ImgBed
4
+ > ClI only
@@ -0,0 +1,6 @@
1
+ import type { IPicGo } from 'picgo';
2
+ declare const _default: (ctx: IPicGo) => {
3
+ uploader: string;
4
+ register: () => void;
5
+ };
6
+ export = _default;
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const form_data_1 = __importDefault(require("form-data"));
6
+ function formatTimestamp() {
7
+ const d = new Date();
8
+ const pad = (n, len = 2) => String(n).padStart(len, '0');
9
+ return (String(d.getFullYear()) +
10
+ pad(d.getMonth() + 1) +
11
+ pad(d.getDate()) +
12
+ pad(d.getHours()) +
13
+ pad(d.getMinutes()) +
14
+ pad(d.getSeconds()) +
15
+ pad(d.getMilliseconds(), 3));
16
+ }
17
+ module.exports = (ctx) => {
18
+ const register = () => {
19
+ ctx.helper.uploader.register('cloudflare-imgbed', {
20
+ async handle(ctx) {
21
+ var _a, _b, _c, _d;
22
+ const config = ctx.getConfig('picBed.cloudflare-imgbed');
23
+ if (!(config === null || config === void 0 ? void 0 : config.baseUrl)) {
24
+ throw new Error('[cloudflare-imgbed] baseUrl is required');
25
+ }
26
+ const baseUrl = config.baseUrl.replace(/\/$/, '');
27
+ const params = new URLSearchParams();
28
+ if (config.authCode)
29
+ params.set('authCode', config.authCode);
30
+ if (config.path)
31
+ params.set('uploadFolder', config.path);
32
+ params.set('uploadNameType', (_a = config.uploadNameType) !== null && _a !== void 0 ? _a : 'origin');
33
+ const query = params.toString();
34
+ const uploadUrl = `${baseUrl}/upload${query ? '?' + query : ''}`;
35
+ for (const img of ctx.output) {
36
+ const ext = (_b = img.extname) !== null && _b !== void 0 ? _b : '.jpg';
37
+ const newFileName = formatTimestamp() + ext;
38
+ const form = new form_data_1.default();
39
+ form.append('file', img.buffer, {
40
+ filename: newFileName,
41
+ contentType: (_c = img.mimeType) !== null && _c !== void 0 ? _c : 'application/octet-stream'
42
+ });
43
+ const res = await ctx.request({
44
+ method: 'POST',
45
+ url: uploadUrl,
46
+ data: form,
47
+ headers: form.getHeaders()
48
+ });
49
+ const body = typeof res === 'string'
50
+ ? JSON.parse(res)
51
+ : (_d = res === null || res === void 0 ? void 0 : res.data) !== null && _d !== void 0 ? _d : res;
52
+ if (!Array.isArray(body) || body.length === 0 || !body[0].src) {
53
+ throw new Error(`[cloudflare-imgbed] unexpected response: ${JSON.stringify(body)}`);
54
+ }
55
+ const src = body[0].src;
56
+ const imgUrl = src.startsWith('http') ? src : `${baseUrl}${src}`;
57
+ img.fileName = newFileName;
58
+ img.imgUrl = imgUrl;
59
+ img.url = imgUrl;
60
+ }
61
+ return ctx;
62
+ },
63
+ config(ctx) {
64
+ var _a, _b, _c, _d, _e;
65
+ const savedConfig = (_a = ctx.getConfig('picBed.cloudflare-imgbed')) !== null && _a !== void 0 ? _a : {};
66
+ return [
67
+ {
68
+ name: 'baseUrl',
69
+ type: 'input',
70
+ default: (_b = savedConfig.baseUrl) !== null && _b !== void 0 ? _b : '',
71
+ required: true,
72
+ message: 'Base URL, e.g. https://your-imgbed.pages.dev',
73
+ alias: 'Instance URL'
74
+ },
75
+ {
76
+ name: 'authCode',
77
+ type: 'input',
78
+ default: (_c = savedConfig.authCode) !== null && _c !== void 0 ? _c : '',
79
+ required: false,
80
+ message: 'Auth Code, leave empty if not set',
81
+ alias: 'Auth Code'
82
+ },
83
+ {
84
+ name: 'path',
85
+ type: 'input',
86
+ default: (_d = savedConfig.path) !== null && _d !== void 0 ? _d : '',
87
+ required: false,
88
+ message: 'Path, e.g. images, blog/images (leave empty for root)',
89
+ alias: 'Upload Path'
90
+ },
91
+ {
92
+ name: 'uploadNameType',
93
+ type: 'list',
94
+ default: (_e = savedConfig.uploadNameType) !== null && _e !== void 0 ? _e : 'origin',
95
+ required: false,
96
+ choices: ['origin', 'default', 'index', 'short'],
97
+ alias: 'Upload Name Type'
98
+ }
99
+ ];
100
+ }
101
+ });
102
+ };
103
+ return {
104
+ uploader: 'cloudflare-imgbed',
105
+ register
106
+ };
107
+ };
@@ -0,0 +1,47 @@
1
+ import path from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+
4
+ import stylistic from '@stylistic/eslint-plugin'
5
+ import { defineConfig } from 'eslint/config'
6
+ import love from 'eslint-config-love'
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
+
10
+ export default defineConfig([
11
+ {
12
+ ignores: ['dist/**'],
13
+ },
14
+ {
15
+ ...love,
16
+ files: ['src/**/*.ts'],
17
+ languageOptions: {
18
+ ...love.languageOptions,
19
+ parserOptions: {
20
+ ...love.languageOptions?.parserOptions,
21
+ tsconfigRootDir: __dirname,
22
+ },
23
+ },
24
+ plugins: {
25
+ ...love.plugins,
26
+ '@stylistic': stylistic,
27
+ },
28
+ rules: {
29
+ ...love.rules,
30
+ 'no-console': 'off',
31
+ semi: 'off',
32
+ '@stylistic/indent': ['error', 2],
33
+ '@stylistic/semi': ['error', 'never'],
34
+ 'no-unexpected-multiline': 'error',
35
+
36
+ '@typescript-eslint/strict-boolean-expressions': 'off',
37
+ '@typescript-eslint/restrict-template-expressions': 'off',
38
+ '@typescript-eslint/require-await': 'off',
39
+ 'no-prototype-builtins': 'off',
40
+ 'no-throw-literal': 'error',
41
+ 'no-unused-expressions': 'error',
42
+ 'no-redeclare': 'error',
43
+ curly: 'error',
44
+ eqeqeq: 'error',
45
+ },
46
+ },
47
+ ])
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "picgo-plugin-cloudflare-imgbed",
3
+ "version": "0.0.1",
4
+ "description": "Third Party PicGo Uploader For MarSeventh/CloudFlare-ImgBed",
5
+ "main": "dist/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "homepage": "",
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "build": "tsc -p .",
13
+ "dev": "tsc -w -p .",
14
+ "lint": "eslint src",
15
+ "patch": "npm version patch && git push origin master && git push origin --tags",
16
+ "minor": "npm version minor && git push origin master && git push origin --tags",
17
+ "major": "npm version major && git push origin master && git push origin --tags"
18
+ },
19
+ "keywords": [
20
+ "picgo",
21
+ "picgo-plugin"
22
+ ],
23
+ "author": "megasuite",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "form-data": "^4.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "picgo": "^1.6.6",
30
+ "@types/node": "22.19.3",
31
+ "typescript": "5.9.3",
32
+ "eslint-config-love": "^144.0.0",
33
+ "eslint": "^9.39.2",
34
+ "@eslint/js": "^9.39.2",
35
+ "globals": "^17.0.0",
36
+ "@stylistic/eslint-plugin": "^5.6.1"
37
+ }
38
+ }