@cocreate/url-uploader 1.0.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/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # CoCreate-url-uploader
2
+
3
+ A simple url-uploader component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API. Take it for a spin in our [playground!](https://cocreate.app/docs/url-uploader)
4
+
5
+ ![min file size in bytes](https://img.badgesize.io/https://cdn.cocreate.app/url-uploader/latest/CoCreate-url-uploader.min.js?style=flat-square&label=minified&color=orange)
6
+ ![gzip file size in bytes](https://img.badgesize.io/https://cdn.cocreate.app/url-uploader/latest/CoCreate-url-uploader.min.js?compression=gzip&style=flat-square&label=gzip&color=yellow)
7
+ ![brotlifile size in bytes](https://img.badgesize.io/https://cdn.cocreate.app/url-uploader/latest/CoCreate-url-uploader.min.js?compression=brotli&style=flat-square&label=brotli)
8
+ ![GitHub latest release](https://img.shields.io/github/v/release/CoCreate-app/CoCreate-url-uploader?style=flat-square)
9
+ ![GitHub](https://img.shields.io/github/license/CoCreate-app/CoCreate-url-uploader?style=flat-square)
10
+ ![GitHub](https://img.shields.io/static/v1?style=flat-square&label=&message=Hiring&color=blueviolet)
11
+
12
+ ![CoCreate-url-uploader](https://cdn.cocreate.app/docs/CoCreate-url-uploader.gif)
13
+
14
+ ## [Docs & Demo](https://cocreate.app/docs/url-uploader)
15
+
16
+ For a complete guide and working demo refer to the [doumentation](https://cocreate.app/docs/url-uploader)
17
+
18
+ ## CDN
19
+
20
+ ```html
21
+ <script src="https://cdn.cocreate.app/url-uploader/latest/CoCreate-url-uploader.min.js"></script>
22
+ ```
23
+
24
+ ```html
25
+ <script src="https://cdn.cocreate.app/url-uploader/latest/CoCreate-url-uploader.min.css"></script>
26
+ ```
27
+
28
+ ## NPM
29
+
30
+ ```shell
31
+ $ npm i @cocreate/url-uploader
32
+ ```
33
+
34
+ ## yarn
35
+
36
+ ```shell
37
+ $ yarn install @cocreate/url-uploader
38
+ ```
39
+
40
+ # Table of Contents
41
+
42
+ - [Table of Contents](#table-of-contents)
43
+ - [Announcements](#announcements)
44
+ - [Roadmap](#roadmap)
45
+ - [How to Contribute](#how-to-contribute)
46
+ - [About](#about)
47
+ - [License](#license)
48
+
49
+ <a name="announcements"></a>
50
+
51
+ # Announcements
52
+
53
+ All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreate-app/CoCreate-url-uploader/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreate-app/CoCreate-url-uploader/releases). You may also subscribe to email for releases and breaking changes.
54
+
55
+ <a name="roadmap"></a>
56
+
57
+ # Roadmap
58
+
59
+ If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreate-app/CoCreate-url-uploader/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-url-uploader/pulls). We would love to hear your feedback.
60
+
61
+ <a name="about"></a>
62
+
63
+ # About
64
+
65
+ CoCreate-url-uploader is guided and supported by the CoCreate Developer Experience Team.
66
+
67
+ Please Email the Developer Experience Team [here](mailto:develop@cocreate.app) in case of any queries.
68
+
69
+ CoCreate-url-uploader is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.
70
+
71
+ <a name="contribute"></a>
72
+
73
+ # How to Contribute
74
+
75
+ We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreate-app/CoCreate-url-uploader/blob/master/CONTRIBUTING.md) guide for details.
76
+
77
+ We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/CoCreate-app/CoCreate-url-uploader/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-url-uploader/pulls) or merely upvote or comment on existing issues or pull requests.
78
+
79
+ We appreciate your continued support, thank you!
80
+
81
+ <a name="license"></a>
82
+
83
+ # License
84
+
85
+ This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license.
86
+
87
+ - **Open Source Use**: For open-source projects and non-commercial use, this software is available under the AGPLv3. The AGPLv3 allows you to freely use, modify, and distribute this software, provided that all modifications and derivative works are also licensed under the AGPLv3. For the full license text, see the [LICENSE file](https://github.com/CoCreate-app/CoCreate-url-uploader/blob/master/LICENSE).
88
+
89
+ - **Commercial Use**: For-profit companies and individuals intending to use this software for commercial purposes must obtain a commercial license. The commercial license is available when you sign up for an API key on our [website](https://cocreate.app). This license permits proprietary use and modification of the software without the copyleft requirements of the AGPLv3. It is ideal for integrating this software into proprietary commercial products and applications.
90
+
91
+ If you have not purchased a commercial license and intend to use this software for commercial purposes, you are required to sign up for an API key on our website.
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <link
8
+ rel="icon"
9
+ type="image/png"
10
+ sizes="32x32"
11
+ href="../assets/favicon.ico" />
12
+ <title>url-uploader | CoCreateJS</title>
13
+ </head>
14
+
15
+ <body>
16
+ <!--<script src="https://cdn.cocreate.app/url-uploader/latest/CoCreate-url-uploader.min.js"></script>-->
17
+ <script src="https://CoCreate.app/dist/CoCreate.js"></script>
18
+ </body>
19
+ </html>
@@ -0,0 +1,228 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <title>CoCreate-url-uploader Documentation | CoCreateJS</title>
8
+ <link
9
+ rel="icon"
10
+ type="image/png"
11
+ sizes="32x32"
12
+ href="https://cocreate.app/images/favicon.ico" />
13
+ <meta
14
+ name="description"
15
+ content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
+ <meta
17
+ name="keywords"
18
+ content="helper classes, utility classes, css framework, css library, inline style classes" />
19
+ <meta name="robots" content="index,follow" />
20
+
21
+ <!-- CoCreate CSS CDN -->
22
+ </head>
23
+
24
+ <body>
25
+ <div array="" object="" key="" id="cocreate-url-uploader">
26
+ <div
27
+ class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
28
+ <div class="display:flex align-items:center">
29
+ <h2>CoCreate-url-uploader</h2>
30
+ </div>
31
+ <div
32
+ class="display:flex align-items:center font-size:20px"
33
+ share-height="600"
34
+ share-width="500"
35
+ share-media="https://via.placeholder.com/300/09f/fff.png">
36
+ <a
37
+ href="https://github.com/CoCreate-app/CoCreate-url-uploader"
38
+ target="_blank"
39
+ class="margin-right:15px"
40
+ ><i class="fab fa-github"></i
41
+ ></a>
42
+ <a
43
+ class="margin-right:15px share"
44
+ share-network="twitter"
45
+ title="Share on twitter"
46
+ ><i class="fab fa-twitter"></i
47
+ ></a>
48
+ <a
49
+ class="margin-right:15px share"
50
+ share-network="facebook"
51
+ title="Share on Facebook"
52
+ ><i class="fab fa-facebook"></i
53
+ ></a>
54
+ <a
55
+ class="margin-right:15px share"
56
+ share-network="instagram"
57
+ title="Share on instagram"
58
+ ><i class="fab fa-instagram"></i
59
+ ></a>
60
+ <a
61
+ class="margin-right:15px share"
62
+ share-network="share"
63
+ title="Share on share"
64
+ ><i class="fas fa-share-alt"></i
65
+ ></a>
66
+ </div>
67
+ </div>
68
+ <h1 class="max-width:500px margin:20px_10px">
69
+ A simple HTML5, CSS and pure javascript component. Easy
70
+ configuration using data-attributes and highly styleable.
71
+ </h1>
72
+ <div id="url-uploader-section" class="display:flex flex-wrap:wrap">
73
+ <div class="flex-grow:1 width:300px padding:20px_10px">
74
+ <h2
75
+ class="border-bottom:1px_solid_lightgrey padding:5px_0px">
76
+ Install
77
+ </h2>
78
+ <pre
79
+ class="margin-top:15px"><code class="language-javascript">npm install cocreate-url-uploader</code></pre>
80
+ <p class="padding:10px_0px">Or you can use cdn link:</p>
81
+ <pre><code class="language-javascript">https://cdn.cocreate.app/js/CoCreate-url-uploader.min.js</code></pre>
82
+
83
+ <h2
84
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
85
+ Usage
86
+ </h2>
87
+ <p class="padding:10px_0px">url-uploader usage content</p>
88
+ <pre><code class="language-html">&lt;div&gt;&lt;/div&gt;</code></pre>
89
+
90
+ <h2
91
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
92
+ Reference
93
+ </h2>
94
+ <p class="padding:10px_0px">
95
+ This is url-uploader reference content
96
+ </p>
97
+ <pre><code class="language-javascript">&lt;div&gt;&lt;/div&gt;</code></pre>
98
+ <p class="padding:10px_0px">
99
+ This is url-uploader reference content
100
+ </p>
101
+
102
+ <h2
103
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
104
+ Attributes
105
+ </h2>
106
+ <ul class="list-style-type:none">
107
+ <li
108
+ class="padding:15px_0px border-bottom:1px_solid_lightgrey">
109
+ <h4>
110
+ <span>url-uploader</span>
111
+ <span class="cocreate-badge success"
112
+ >string</span
113
+ >
114
+ <span class="cocreate-badge warning"
115
+ >optional</span
116
+ >
117
+ </h4>
118
+ <p>url-uploader-attribute</p>
119
+ </li>
120
+ <li
121
+ class="padding:15px_0px border-bottom:1px_solid_lightgrey">
122
+ <h4>
123
+ <span>url-uploader</span>
124
+ <span class="cocreate-badge success"
125
+ >string</span
126
+ >
127
+ <span class="cocreate-badge warning"
128
+ >optional</span
129
+ >
130
+ </h4>
131
+ <p>url-uploader-attribute</p>
132
+ </li>
133
+ </ul>
134
+ </div>
135
+
136
+ <div
137
+ class="flex-grow:1 width:300px padding:0px_10px margin:20px_0px border-bottom:1px_solid_lightgrey">
138
+ <!-- SandBox -->
139
+ <h2
140
+ class="border-bottom:1px_solid_lightgrey padding:5px_0px">
141
+ Demo
142
+ </h2>
143
+ <div
144
+ class="position:sticky top:0 padding:10px_0px height:100vh">
145
+ <!-- SandBox -->
146
+ <div
147
+ class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
148
+ id="playground">
149
+ <div
150
+ id="demo-code"
151
+ resizable
152
+ class="position:relative height:50%">
153
+ <textarea
154
+ type="code"
155
+ lang="html"
156
+ array="demos"
157
+ object=""
158
+ key="demo"
159
+ save="false"
160
+ id="demo"
161
+ class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
162
+ <div
163
+ resize="bottom"
164
+ class="background:lightgrey"></div>
165
+ </div>
166
+
167
+ <div
168
+ id="demo-preview"
169
+ class="position:relative overflow:auto background-color:white">
170
+ <div
171
+ get-value="#demo"
172
+ class="padding:20px"></div>
173
+ </div>
174
+
175
+ <div
176
+ class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
177
+ <a
178
+ class="margin-right:10px"
179
+ id="eye"
180
+ show="#eye-slash"
181
+ hide="#eye, #demo-preview"
182
+ toggle="code-height"
183
+ toggle-selector="#demo-code"
184
+ ><i class="far fa-eye"></i
185
+ ></a>
186
+ <a
187
+ class="margin-right:10px"
188
+ hidden
189
+ id="eye-slash"
190
+ show="#eye, #demo-preview"
191
+ hide="#eye-slash"
192
+ toggle="code-height"
193
+ toggle-selector="#demo-code"
194
+ ><i class="fas fa-eye-slash"></i
195
+ ></a>
196
+ <a
197
+ class="margin-right:10px"
198
+ id="code"
199
+ show="#code-slash"
200
+ hide="#code, #demo-code"
201
+ ><i class="fa fa-code"></i
202
+ ></a>
203
+ <a
204
+ class="margin-right:10px"
205
+ hidden
206
+ id="code-slash"
207
+ show="#code, #demo-code"
208
+ hide="#code-slash"
209
+ ><i class="fas fa-code"></i
210
+ ></a>
211
+ <a
212
+ class="margin-right:5px"
213
+ fullscreen
214
+ target="#playground"
215
+ ><i class="fas fa-expand"></i
216
+ ></a>
217
+ </div>
218
+ </div>
219
+ <!-- End SandBox -->
220
+ </div>
221
+ </div>
222
+ </div>
223
+ </div>
224
+
225
+ <!--CoCreateJS-->
226
+ <script src="https://CoCreate.app/dist/CoCreate.js"></script>
227
+ </body>
228
+ </html>
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@cocreate/url-uploader",
3
+ "version": "1.0.0",
4
+ "description": "A simple url-uploader component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
+ "keywords": [
6
+ "url-uploader",
7
+ "cocreate",
8
+ "low-code-framework",
9
+ "no-code-framework",
10
+ "cocreatejs",
11
+ "cocreatejs-component",
12
+ "cocreate-framework",
13
+ "no-code",
14
+ "low-code",
15
+ "collaborative-framework",
16
+ "realtime",
17
+ "realtime-framework",
18
+ "collaboration",
19
+ "shared-editing",
20
+ "html5-framework",
21
+ "javascript-framework"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "start": "npx webpack --config webpack.config.js",
28
+ "build": "npx webpack --mode=production --config webpack.config.js",
29
+ "dev": "npx webpack --config webpack.config.js --watch",
30
+ "postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\""
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/CoCreate-app/CoCreate-url-uploader.git"
35
+ },
36
+ "author": "CoCreate LLC",
37
+ "license": "AGPL-3.0",
38
+ "bugs": {
39
+ "url": "https://github.com/CoCreate-app/CoCreate-url-uploader/issues"
40
+ },
41
+ "homepage": "https://cocreate.app/docs/url-uploader",
42
+ "funding": {
43
+ "type": "GitHub Sponsors ❤",
44
+ "url": "https://github.com/sponsors/CoCreate-app"
45
+ },
46
+ "main": "./src/index.js",
47
+ "dependencies": {
48
+ "node-fetch": "^3.3.2"
49
+ }
50
+ }
@@ -0,0 +1,22 @@
1
+ module.exports = {
2
+ dryRun: false,
3
+ branches: ["master"],
4
+ plugins: [
5
+ "@semantic-release/commit-analyzer",
6
+ "@semantic-release/release-notes-generator",
7
+ [
8
+ "@semantic-release/changelog",
9
+ {
10
+ changelogFile: "CHANGELOG.md",
11
+ },
12
+ ],
13
+ "@semantic-release/npm",
14
+ "@semantic-release/github",
15
+ [
16
+ "@semantic-release/git",
17
+ {
18
+ assets: ["CHANGELOG.md", "package.json"],
19
+ },
20
+ ],
21
+ ],
22
+ };
package/src/index.js ADDED
@@ -0,0 +1,87 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2023 CoCreate and Contributors.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published
6
+ * by the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+ ********************************************************************************/
17
+
18
+ // Commercial Licensing Information:
19
+ // For commercial use of this software without the copyleft provisions of the AGPLv3,
20
+ // you must obtain a commercial license from CoCreate LLC.
21
+ // For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
22
+
23
+
24
+ const { URL } = require('url');
25
+
26
+ class CoCreateUrlUploader {
27
+ constructor(crud) {
28
+ this.crud = crud
29
+ crud.wsManager.on('importUrl', async (data) => {
30
+ this.fetchFileFromURL(data)
31
+ });
32
+ }
33
+
34
+
35
+ async fetchFileFromURL(data) {
36
+ try {
37
+ const file = data.file
38
+ const fetch = await import('node-fetch').then(module => module.default);
39
+ const response = await fetch(file.src);
40
+
41
+ if (!response.ok) {
42
+ throw new Error('Failed to fetch file: ' + response.statusText);
43
+ }
44
+
45
+ const arrayBuffer = await response.arrayBuffer();
46
+ file.src = arrayBufferToBase64(arrayBuffer)
47
+
48
+ file.size = arrayBuffer.byteLength
49
+ file['content-type'] = response.headers.get('content-type')
50
+
51
+ if (!file.name) {
52
+ const parsedUrl = new URL(file.src);
53
+ file.name = parsedUrl.pathname.split('/').pop();
54
+ }
55
+
56
+ if (!file.directory)
57
+ file.directory = '/'
58
+ if (!file.path)
59
+ file.path = file.directory
60
+ if (!file.pathname) {
61
+ if (file.path.endsWith('/'))
62
+ file.pathname = file.path + file.name
63
+ else
64
+ file.pathname = file.path + '/' + file.name
65
+ }
66
+ if (data.socket)
67
+ this.crud.wsManager.send(data)
68
+
69
+ // return data;
70
+ } catch (error) {
71
+ console.error('Error fetching file:', error);
72
+ throw error;
73
+ }
74
+ }
75
+
76
+ arrayBufferToBase64(buffer) {
77
+ let binary = '';
78
+ const bytes = new Uint8Array(buffer);
79
+ const len = bytes.byteLength;
80
+ for (let i = 0; i < len; i++) {
81
+ binary += String.fromCharCode(bytes[i]);
82
+ }
83
+ return Buffer.from(binary, 'binary').toString('base64');
84
+ }
85
+ }
86
+
87
+ module.exports = CoCreateUrlUploader;