Skip to content

Commit

Permalink
Fix issue with uploading top image files
Browse files Browse the repository at this point in the history
Closes #21
  • Loading branch information
dsevillamartin committed Aug 26, 2020
1 parent 1836194 commit 066614c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@

(new Extend\Routes('api'))
->post('/fof/gamification/convert', 'fof.gamification.convert', Controllers\ConvertLikesController::class)
->post('/fof/gamification/topimage{id}', 'fof.topImage.add', Controllers\UploadTopImageController::class)
->delete('/fof/gamification/topimage{id}', 'fof.topImage.delete', Controllers\DeleteTopImageController::class)
->get('/ranks', 'ranks.index', Controllers\ListRanksController::class)
->post('/ranks', 'ranks.create', Controllers\CreateRankController::class)
->post('/topimage{id}', 'fof.topImage.add', Controllers\UploadTopImageController::class)
->delete('/topimage{id}', 'fof.topImage.delete', Controllers\DeleteTopImageController::class)
->patch('/ranks/{id}', 'ranks.update', Controllers\UpdateRankController::class)
->delete('/ranks/{id}', 'ranks.delete', Controllers\DeleteRankController::class)
->get('/rankings', 'rankings', Controllers\OrderByPointsController::class),
Expand Down
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions js/src/admin/components/SettingsPage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Alert from 'flarum/components/Alert';
import Page from 'flarum/components/Page';
import Button from 'flarum/components/Button';
import UploadImageButton from 'flarum/components/UploadImageButton';
import saveSettings from 'flarum/utils/saveSettings';
import Switch from 'flarum/components/Switch';
import UploadImageButton from './UploadImageButton';

export default class SettingsPage extends Page {
init() {
Expand Down Expand Up @@ -195,15 +195,17 @@ export default class SettingsPage extends Page {
oninput: m.withAttr('value', this.values.blockedUsers),
}),
m('div', { className: 'helpText' }, app.translator.trans('fof-gamification.admin.page.rankings.blocked.help')),
m('label', { className: 'Upload-label' }, app.translator.trans('fof-gamification.admin.page.rankings.custom_image_1')),
<UploadImageButton className="Upload-button" name="fof-gamification.topimage1" />,
m('br'),
m('label', { className: 'Upload-label' }, app.translator.trans('fof-gamification.admin.page.rankings.custom_image_2')),
<UploadImageButton className="Upload-button" name="fof-gamification.topimage2" />,
m('br'),
m('label', { className: 'Upload-label' }, app.translator.trans('fof-gamification.admin.page.rankings.custom_image_3')),
<UploadImageButton className="Upload-button" name="fof-gamification.topimage3" />,
m('br'),
...[1, 2, 3].map((num) => [
<label className="Upload-label">
{app.translator.trans(`fof-gamification.admin.page.rankings.custom_image_${num}`)}
</label>,
<UploadImageButton
className="Upload-button"
name={`fof-gamification.topimage${num}`}
path={`fof/gamification/topimage${num}`}
/>,
<br />,
]),
Button.component({
type: 'submit',
className: 'Button Button--primary Ranks-save',
Expand Down
7 changes: 7 additions & 0 deletions js/src/admin/components/UploadImageButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import FlarumUploadImageButton from 'flarum/components/UploadImageButton';

export default class UploadImageButton extends FlarumUploadImageButton {
resourceUrl() {
return app.forum.attribute('apiUrl') + '/' + this.props.path;
}
}
5 changes: 2 additions & 3 deletions src/Api/Controllers/UploadTopImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Flarum\Foundation\Application;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\AssertPermissionTrait;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Intervention\Image\ImageManager;
use League\Flysystem\Adapter\Local;
Expand Down Expand Up @@ -52,13 +53,11 @@ public function data(ServerRequestInterface $request, Document $document)

$id = array_get($request->getQueryParams(), 'id');

$file = array_get($request->getUploadedFiles(), 'topimage'.$id);
$file = Arr::first($request->getUploadedFiles());

$tmpFile = tempnam($this->app->storagePath().'/tmp', 'topimage.'.$id);
$file->moveTo($tmpFile);

$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);

if ('1' == $id) {
$size = 125;
} elseif ('2' == $id) {
Expand Down

0 comments on commit 066614c

Please sign in to comment.