1
0
Fork 0

Update compose APIs

This commit is contained in:
Daniel Supernault 2018-12-02 18:42:55 -07:00
parent 111a627048
commit 0376a497ba
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
2 changed files with 37 additions and 5 deletions

View File

@ -8,9 +8,15 @@ use App\Http\Controllers\{
AvatarController AvatarController
}; };
use Auth, Cache, URL; use Auth, Cache, URL;
use App\{Avatar,Media,Profile}; use App\{
Avatar,
Notification,
Media,
Profile
};
use App\Transformer\Api\{ use App\Transformer\Api\{
AccountTransformer, AccountTransformer,
NotificationTransformer,
MediaTransformer, MediaTransformer,
StatusTransformer StatusTransformer
}; };
@ -35,6 +41,15 @@ class BaseApiController extends Controller
$this->fractal->setSerializer(new ArraySerializer()); $this->fractal->setSerializer(new ArraySerializer());
} }
public function notification(Request $request, $id)
{
$notification = Notification::findOrFail($id);
$resource = new Fractal\Resource\Item($notification, new NotificationTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
}
public function accounts(Request $request, $id) public function accounts(Request $request, $id)
{ {
$profile = Profile::findOrFail($id); $profile = Profile::findOrFail($id);
@ -173,6 +188,11 @@ class BaseApiController extends Controller
$photo = $request->file('file'); $photo = $request->file('file');
$mimes = explode(',', config('pixelfed.media_types'));
if(in_array($photo->getMimeType(), $mimes) == false) {
return;
}
$storagePath = "public/m/{$monthHash}/{$userHash}"; $storagePath = "public/m/{$monthHash}/{$userHash}";
$path = $photo->store($storagePath); $path = $photo->store($storagePath);
$hash = \hash_file('sha256', $photo); $hash = \hash_file('sha256', $photo);
@ -183,8 +203,8 @@ class BaseApiController extends Controller
$media->user_id = $user->id; $media->user_id = $user->id;
$media->media_path = $path; $media->media_path = $path;
$media->original_sha256 = $hash; $media->original_sha256 = $hash;
$media->size = $photo->getClientSize(); $media->size = $photo->getSize();
$media->mime = $photo->getClientMimeType(); $media->mime = $photo->getMimeType();
$media->filter_class = null; $media->filter_class = null;
$media->filter_name = null; $media->filter_name = null;
$media->save(); $media->save();

View File

@ -93,8 +93,15 @@ class StatusController extends Controller
$photos = $request->file('photo'); $photos = $request->file('photo');
$order = 1; $order = 1;
$mimes = []; $mimes = [];
$medias = 0;
foreach ($photos as $k => $v) { foreach ($photos as $k => $v) {
$allowedMimes = explode(',', config('pixelfed.media_types'));
if(in_array($v->getMimeType(), $allowedMimes) == false) {
continue;
}
$storagePath = "public/m/{$monthHash}/{$userHash}"; $storagePath = "public/m/{$monthHash}/{$userHash}";
$path = $v->store($storagePath); $path = $v->store($storagePath);
$hash = \hash_file('sha256', $v); $hash = \hash_file('sha256', $v);
@ -104,8 +111,8 @@ class StatusController extends Controller
$media->user_id = $user->id; $media->user_id = $user->id;
$media->media_path = $path; $media->media_path = $path;
$media->original_sha256 = $hash; $media->original_sha256 = $hash;
$media->size = $v->getClientSize(); $media->size = $v->getSize();
$media->mime = $v->getClientMimeType(); $media->mime = $v->getMimeType();
$media->filter_class = $request->input('filter_class'); $media->filter_class = $request->input('filter_class');
$media->filter_name = $request->input('filter_name'); $media->filter_name = $request->input('filter_name');
$media->order = $order; $media->order = $order;
@ -113,8 +120,13 @@ class StatusController extends Controller
array_push($mimes, $media->mime); array_push($mimes, $media->mime);
ImageOptimize::dispatch($media); ImageOptimize::dispatch($media);
$order++; $order++;
$medias++;
} }
if($medias == 0) {
$status->delete();
return;
}
$status->type = (new self)::mimeTypeCheck($mimes); $status->type = (new self)::mimeTypeCheck($mimes);
$status->save(); $status->save();