Add upload_file.sh and update file-upload view accordingly
This commit is contained in:
parent
669325d029
commit
36105e86a5
18
assets/files/upload_file.sh
Executable file
18
assets/files/upload_file.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
local_file=$1
|
||||
token=$(cat $HOME/.ily_token)
|
||||
|
||||
if test -z "$2"; then
|
||||
curl -X POST -H 'Accept: text/plain' \
|
||||
-H "Authorization: $token" \
|
||||
-F 'upload=@'$local_file \
|
||||
-F 'ttl=2592000' \
|
||||
https://ily.li/
|
||||
else
|
||||
curl -X PUT -H 'Accept: text/plain' \
|
||||
-H "Authorization: $token" \
|
||||
-F 'upload=@'$local_file \
|
||||
-F 'ttl=2592000' \
|
||||
"https://ily.li/$2"
|
||||
fi
|
@ -15,6 +15,7 @@ const SLUG_DICTIONARY = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012
|
||||
export default class FileController extends Controller {
|
||||
routes(): void {
|
||||
this.get('/files/upload', this.getFileUploader, 'file-upload', REQUIRE_AUTH_MIDDLEWARE);
|
||||
this.get('/files/upload/script', this.downloadLinuxScript, 'linux-script');
|
||||
this.post('/files/post', this.postFileFrontend, 'post-file-frontend', REQUIRE_AUTH_MIDDLEWARE, FILE_UPLOAD_FORM_MIDDLEWARE);
|
||||
this.get('/files/:page([0-9]+)?', this.getFileManager, 'file-manager', REQUIRE_AUTH_MIDDLEWARE);
|
||||
this.get('/files/delete/:slug', this.deleteFile, 'delete-file-frontend', REQUIRE_AUTH_MIDDLEWARE);
|
||||
@ -34,6 +35,10 @@ export default class FileController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
protected async downloadLinuxScript(req: Request, res: Response): Promise<void> {
|
||||
res.download('assets/files/upload_file.sh', 'upload_file.sh');
|
||||
}
|
||||
|
||||
protected async getFileManager(req: Request, res: Response): Promise<void> {
|
||||
res.render('file-manager', {
|
||||
files: await FileModel.paginateForUser(req, 100, req.models.user!.id!),
|
||||
|
@ -46,13 +46,29 @@
|
||||
<h2>Setup a desktop utility</h2>
|
||||
<p>There may be a desktop client at some point. For now, if you're an advanced user, you can setup
|
||||
scripts/macros.</p>
|
||||
|
||||
<hr>
|
||||
<section>
|
||||
<h3>First alternative: sh script (native on linux)</h3>
|
||||
<p>If you have the sh shell on your machine (i.e. you are on linux, git bash on windows...), you can
|
||||
<a href="{{ route('linux-script') }}">download this script</a>.</p>
|
||||
<p>You must put a valid auth token (generated in the form at the bottom of this page) in a .ily_token file in your home directory ($HOME/.ily_token).</p>
|
||||
<p>Examples:</p>
|
||||
<pre>upload_script.sh path/to/file</pre>
|
||||
<pre>upload_script.sh path/to/file my_very_important_file.png</pre>
|
||||
</section>
|
||||
|
||||
<hr>
|
||||
|
||||
<section>
|
||||
<h3>Second alternative: implement your own client</h3>
|
||||
<p>
|
||||
To upload the file, you must:
|
||||
</p>
|
||||
<ul>
|
||||
<li>Set the "Authorization" HTTP header to an auth token (generate one with the form below)</li>
|
||||
<li>Make a proper file upload request either with the method "POST" on / (auto-generates a short url) or
|
||||
"PUT" (choose the target url you want, alphanum)
|
||||
<li>Make a proper file upload request either with the method "POST" on / (auto-generates a short
|
||||
url) or "PUT" (choose the target url you want, alphanum)
|
||||
</li>
|
||||
</ul>
|
||||
<table class="data-table">
|
||||
@ -96,6 +112,7 @@ https://ily.li/my_very_important_file.png</pre>
|
||||
-F 'ttl=30' \
|
||||
https://ily.li/</pre>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="panel">
|
||||
@ -130,8 +147,7 @@ https://ily.li/</pre>
|
||||
<td>{{ token.created_at.toISOString() }}</td>
|
||||
<td>{{ token.used_at.toISOString() }}</td>
|
||||
<td>
|
||||
<a href="{{ route('revoke-token', token.id) }}" class="button danger"><i
|
||||
data-feather="trash"></i> Revoke</a>
|
||||
<a href="{{ route('revoke-token', token.id) }}" class="button danger"><i data-feather="trash"></i> Revoke</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user