mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-23 08:14:10 +00:00
Add MicroController
This commit is contained in:
parent
853f98c0f4
commit
d0361dd9ff
1 changed files with 67 additions and 0 deletions
67
app/Http/Controllers/MicroController.php
Normal file
67
app/Http/Controllers/MicroController.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\{
|
||||
Profile,
|
||||
Status,
|
||||
};
|
||||
use Auth, DB, Purify;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MicroController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function composeText(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'type' => [
|
||||
'required',
|
||||
'string',
|
||||
Rule::in(['text'])
|
||||
],
|
||||
'title' => 'nullable|string|max:140',
|
||||
'content' => 'required|string|max:500',
|
||||
'visibility' => [
|
||||
'required',
|
||||
'string',
|
||||
Rule::in([
|
||||
'public',
|
||||
'unlisted',
|
||||
'private',
|
||||
'draft'
|
||||
])
|
||||
]
|
||||
]);
|
||||
$profile = Auth::user()->profile;
|
||||
$title = $request->input('title');
|
||||
$content = $request->input('content');
|
||||
$visibility = $request->input('visibility');
|
||||
|
||||
$status = DB::transaction(function() use($profile, $content, $visibility, $title) {
|
||||
$status = new Status;
|
||||
$status->type = 'text';
|
||||
$status->profile_id = $profile->id;
|
||||
$status->caption = strip_tags($content);
|
||||
$status->rendered = Purify::clean($content);
|
||||
$status->is_nsfw = false;
|
||||
|
||||
// TODO: remove deprecated visibility in favor of scope
|
||||
$status->visibility = $visibility;
|
||||
$status->scope = $visibility;
|
||||
$status->entities = json_encode(['title'=>$title]);
|
||||
$status->save();
|
||||
return $status;
|
||||
});
|
||||
|
||||
$fractal = new \League\Fractal\Manager();
|
||||
$fractal->setSerializer(new \League\Fractal\Serializer\ArraySerializer());
|
||||
$s = new \League\Fractal\Resource\Item($status, new \App\Transformer\Api\StatusTransformer());
|
||||
return $fractal->createData($s)->toArray();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue