1
0
Fork 0

Merge pull request #1956 from pixelfed/staging

Update StoryController, orientate story media and strip exif
This commit is contained in:
daniel 2020-01-22 16:05:20 -07:00 committed by GitHub
commit 5c007883c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 17 deletions

View File

@ -15,6 +15,7 @@
- Updated presenter components, load fallback image on errors ([273170c5](https://github.com/pixelfed/pixelfed/commit/273170c5)) - Updated presenter components, load fallback image on errors ([273170c5](https://github.com/pixelfed/pixelfed/commit/273170c5))
- Updated Story model, hide json attribute by default ([de89403c](https://github.com/pixelfed/pixelfed/commit/de89403c)) - Updated Story model, hide json attribute by default ([de89403c](https://github.com/pixelfed/pixelfed/commit/de89403c))
- Updated compose view, add deprecation notice for v3 ([57e155b9](https://github.com/pixelfed/pixelfed/commit/57e155b9)) - Updated compose view, add deprecation notice for v3 ([57e155b9](https://github.com/pixelfed/pixelfed/commit/57e155b9))
- Updated StoryController, orientate story media and strip exif ([07a13fcf](https://github.com/pixelfed/pixelfed/commit/07a13fcf))
### Changed ### Changed

View File

@ -10,6 +10,7 @@ use App\Story;
use App\StoryView; use App\StoryView;
use App\Services\StoryService; use App\Services\StoryService;
use Cache, Storage; use Cache, Storage;
use Image as Intervention;
use App\Services\FollowerService; use App\Services\FollowerService;
@ -41,23 +42,8 @@ class StoryController extends Controller
abort(400, 'You have reached your limit for new Stories today.'); abort(400, 'You have reached your limit for new Stories today.');
} }
$monthHash = substr(hash('sha1', date('Y').date('m')), 0, 12);
$sid = Str::uuid();
$rid = Str::random(6).'.'.Str::random(9);
$photo = $request->file('file'); $photo = $request->file('file');
$path = $this->storePhoto($photo);
$mimes = explode(',', config('pixelfed.media_types'));
if(in_array($photo->getMimeType(), [
'image/jpeg',
'image/png'
]) == false) {
abort(400, 'Invalid media type');
return;
}
$storagePath = "public/_esm.t1/{$monthHash}/{$sid}/{$rid}";
$path = $photo->store($storagePath);
$story = new Story(); $story = new Story();
$story->duration = 3; $story->duration = 3;
@ -77,6 +63,30 @@ class StoryController extends Controller
]; ];
} }
protected function storePhoto($photo)
{
$monthHash = substr(hash('sha1', date('Y').date('m')), 0, 12);
$sid = Str::uuid();
$rid = Str::random(6).'.'.Str::random(9);
$mimes = explode(',', config('pixelfed.media_types'));
if(in_array($photo->getMimeType(), [
'image/jpeg',
'image/png'
]) == false) {
abort(400, 'Invalid media type');
return;
}
$storagePath = "public/_esm.t1/{$monthHash}/{$sid}/{$rid}";
$path = $photo->store($storagePath);
$fpath = storage_path('app/' . $path);
$img = Intervention::make($fpath);
$img->orientate();
$img->save($fpath, config('pixelfed.image_quality'));
$img->destroy();
return $path;
}
public function apiV1Delete(Request $request, $id) public function apiV1Delete(Request $request, $id)
{ {
abort_if(!config('instance.stories.enabled') || !$request->user(), 404); abort_if(!config('instance.stories.enabled') || !$request->user(), 404);
@ -107,9 +117,9 @@ class StoryController extends Controller
$groupBy = config('database.default') == 'pgsql' ? 'id' : 'profile_id'; $groupBy = config('database.default') == 'pgsql' ? 'id' : 'profile_id';
$stories = Story::with('profile') $stories = Story::with('profile')
->groupBy($groupBy)
->whereIn('profile_id', $following) ->whereIn('profile_id', $following)
->where('expires_at', '>', now()) ->where('expires_at', '>', now())
->groupBy($groupBy)
->orderByDesc('expires_at') ->orderByDesc('expires_at')
->take(9) ->take(9)
->get() ->get()