Generate config for ShareX
Display file size
This commit is contained in:
parent
37e06e7c40
commit
765fbdeb25
9 changed files with 62 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
## v1.2
|
||||
+ Previews are now scaled for better page load.
|
||||
+ Added auto config generator for ShareX.
|
||||
+ Show upload file size on the dashboard.
|
||||
+ Fixed insert for admin user (running `php bin\migrate --install`).
|
||||
|
||||
## v1.1
|
||||
+ Added logging.
|
||||
+ Fixed back to top when click delete or publish/unpublish.
|
||||
|
|
|
@ -43,11 +43,13 @@ class DashboardController extends Controller
|
|||
$extension = pathinfo($media->filename, PATHINFO_EXTENSION);
|
||||
try {
|
||||
$mime = $filesystem->getMimetype($media->storage_path);
|
||||
$size = $filesystem->getSize($media->storage_path);
|
||||
} catch (FileNotFoundException $e) {
|
||||
$mime = null;
|
||||
}
|
||||
$media->mimetype = $mime;
|
||||
$media->extension = $extension;
|
||||
$media->size = $this->humanFilesize($size);
|
||||
|
||||
if ($type = explode('/', $mime)[0] === 'image') {
|
||||
$this->http2push("$base_url/$media->user_code/$media->code.$extension/raw");
|
||||
|
|
|
@ -282,6 +282,43 @@ class UserController extends Controller
|
|||
echo $token;
|
||||
}
|
||||
|
||||
public function getShareXconfigFile($id): void
|
||||
{
|
||||
$this->checkLogin();
|
||||
|
||||
$user = DB::query('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', $id)->fetch();
|
||||
|
||||
if (!$user) {
|
||||
Flight::halt(404);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user->id !== Session::get('user_id') && !Session::get('admin', false)) {
|
||||
Flight::halt(403);
|
||||
return;
|
||||
}
|
||||
|
||||
$base_url = Flight::get('config')['base_url'];
|
||||
$json = [
|
||||
'DestinationType' => 'ImageUploader, TextUploader, FileUploader',
|
||||
'RequestURL' => "$base_url/upload",
|
||||
'FileFormName' => 'upload',
|
||||
'Arguments' => [
|
||||
'file' => '$filename$',
|
||||
'text' => '$input$',
|
||||
'token' => $user->token,
|
||||
],
|
||||
'URL' => '$json:url$',
|
||||
'ThumbnailURL' => '$json:url$/raw',
|
||||
];
|
||||
|
||||
Flight::response()->header('Content-Type', 'application/json');
|
||||
Flight::response()->header('Content-Disposition', 'attachment;filename="' . $user->username . '-ShareX.sxcu"');
|
||||
Flight::response()->sendHeaders();
|
||||
|
||||
echo json_encode($json, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
protected function generateNewToken(): string
|
||||
{
|
||||
do {
|
||||
|
|
|
@ -17,6 +17,7 @@ Flight::route('GET /user/@id/delete', [\App\Controllers\UserController::instance
|
|||
Flight::route('GET /profile', [\App\Controllers\UserController::instance(), 'profile']);
|
||||
Flight::route('POST /profile/@id/edit', [\App\Controllers\UserController::instance(), 'profileEdit']);
|
||||
Flight::route('POST /user/@id/refreshToken', [\App\Controllers\UserController::instance(), 'refreshToken']);
|
||||
Flight::route('GET /user/@id/config/sharex', [\App\Controllers\UserController::instance(), 'getShareXconfigFile']);
|
||||
|
||||
Flight::route('POST /upload', [\App\Controllers\UploadController::instance(), 'upload']);
|
||||
Flight::route('POST /upload/@id/publish', [\App\Controllers\UploadController::instance(), 'togglePublish']);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<tr>
|
||||
<th>Preview</th>
|
||||
<th>Filename</th>
|
||||
<th>Size</th>
|
||||
<th>Public</th>
|
||||
<th>Owner</th>
|
||||
<th>Date</th>
|
||||
|
@ -40,6 +41,7 @@
|
|||
{% endif %}
|
||||
</td>
|
||||
<td>{{ media.filename }}</td>
|
||||
<td>{{ media.size }}</td>
|
||||
<td id="published_{{ media.id }}">
|
||||
{% if media.published %}
|
||||
<span class="badge badge-success"><i class="fas fa-check"></i></span>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
<p class="card-text">{{ media.filename }}</p>
|
||||
<p class="card-text">{{ media.filename }}<small class="float-right">{{ media.size }}</small></p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-sm btn-outline-success btn-clipboard" data-toggle="tooltip" title="Copy link" data-clipboard-text="{{ config.base_url }}/{{ media.user_code }}/{{ media.code }}.{{ media.extension }}">
|
||||
|
|
|
@ -43,6 +43,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Client Config</label>
|
||||
<div class="col-sm-10">
|
||||
<a href="{{ config.base_url }}/user/{{ user.id }}/config/sharex" class="btn btn-lg btn-outline-dark"><i class="fas fa-fw fa-download"></i> ShareX Config File</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-2"></div>
|
||||
<div class="col-sm-10">
|
||||
|
|
|
@ -42,6 +42,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Client Config</label>
|
||||
<div class="col-sm-10">
|
||||
<a href="{{ config.base_url }}/user/{{ user.id }}/config/sharex" class="btn btn-lg btn-outline-dark"><i class="fas fa-fw fa-download"></i> ShareX Config File</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row justify-content-md-end">
|
||||
<div class="col-sm-10">
|
||||
<button type="submit" class="btn btn-outline-info">
|
||||
|
|
|
@ -6,6 +6,7 @@ html {
|
|||
|
||||
body {
|
||||
margin-bottom: 40px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
|
|
Loading…
Reference in a new issue