diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index 35bba5c9a..6d62ab07d 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -45,6 +45,7 @@ use App\Services\ServiceService; use Illuminate\Support\Str; use App\Util\Lexer\Autolink; use App\Util\Lexer\Extractor; +use App\Util\Media\License; class ComposeController extends Controller { @@ -407,6 +408,7 @@ class ComposeController extends Controller 'place' => 'nullable', 'comments_disabled' => 'nullable', 'tagged' => 'nullable', + 'license' => 'nullable|integer|min:1|max:16' // 'optimize_media' => 'nullable' ]); @@ -439,6 +441,8 @@ class ComposeController extends Controller abort_if($limitReached == true, 429); + $license = in_array($request->input('license'), License::keys()) ? $request->input('license') : null; + $visibility = $request->input('visibility'); $medias = $request->input('media'); $attachments = []; @@ -458,7 +462,7 @@ class ComposeController extends Controller abort(403, 'Invalid media id'); } $m->filter_class = in_array($media['filter_class'], Filter::classes()) ? $media['filter_class'] : null; - $m->license = $media['license']; + $m->license = $license; $m->caption = isset($media['alt']) ? strip_tags($media['alt']) : null; $m->order = isset($media['cursor']) && is_int($media['cursor']) ? (int) $media['cursor'] : $k; // if($optimize_media == false) { diff --git a/app/Media.php b/app/Media.php index 3854c3848..107f15b4d 100644 --- a/app/Media.php +++ b/app/Media.php @@ -4,6 +4,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use App\Util\Media\License; use Storage; class Media extends Model @@ -101,4 +102,25 @@ class Media extends Model return $meta['Model']; } } + + public function getLicense() + { + $license = $this->license; + + if(!$license || strlen($license) > 2 || $license == 1) { + return null; + } + + if(!in_array($license, License::keys())) { + return null; + } + + $res = License::get()[$license]; + + return [ + 'id' => $res['id'], + 'title' => $res['title'], + 'url' => $res['url'] + ]; + } } diff --git a/app/Transformer/Api/MediaDraftTransformer.php b/app/Transformer/Api/MediaDraftTransformer.php index bb531f556..1f6c578c0 100644 --- a/app/Transformer/Api/MediaDraftTransformer.php +++ b/app/Transformer/Api/MediaDraftTransformer.php @@ -10,14 +10,6 @@ class MediaDraftTransformer extends Fractal\TransformerAbstract { public function transform(Media $media) { - - $url = URL::temporarySignedRoute( - 'temp-media', now()->addHours(1), ['profileId' => $media->profile_id, 'mediaId' => $media->id, 'timestamp' => time()] - ); - - //$url = $media->thumbnailUrl(); - //$url = $media->url(); - return [ 'id' => (string) $media->id, 'type' => $media->activityVerb(), diff --git a/app/Transformer/Api/MediaTransformer.php b/app/Transformer/Api/MediaTransformer.php index a5d0a0adb..21c0b25b5 100644 --- a/app/Transformer/Api/MediaTransformer.php +++ b/app/Transformer/Api/MediaTransformer.php @@ -15,10 +15,11 @@ class MediaTransformer extends Fractal\TransformerAbstract 'url' => $media->url(), 'remote_url' => null, 'preview_url' => $media->thumbnailUrl(), + 'optimized_url' => $media->optimized_url, 'text_url' => null, 'meta' => null, 'description' => $media->caption, - 'license' => $media->license, + 'license' => $media->getLicense(), 'is_nsfw' => $media->is_nsfw, 'orientation' => $media->orientation, 'filter_name' => $media->filter_name, diff --git a/app/Util/Media/License.php b/app/Util/Media/License.php new file mode 100644 index 000000000..653013a4d --- /dev/null +++ b/app/Util/Media/License.php @@ -0,0 +1,123 @@ + [ + "id" => 1, + "title" => "All Rights Reserved", + "name" => "All Rights Reserved", + "description" => "You, the copyright holder, reserve all rights provided by copyright law, such as the right to make copies, distribute your work, perform your work, license, or otherwise exploit your work; no rights are waived under this license.", + "terms" => [], + "url" => url('/site/kb/licenses') + ], + 5 => [ + "id" => 5, + "title" => "Public Domain", + "name" => "Public Domain Work", + "description" => "Works, or aspects of copyrighted works, which copyright law does not protect.", + "terms" => [], + "url" => url('/site/kb/licenses') + ], + 6 => [ + "id" => 6, + "title" => "Public Domain (CC0)", + "name" => "Public Domain Dedication (CC0)", + "description" => "You, the copyright holder, waive your interest in your work and place the work as completely as possible in the public domain so others may freely exploit and use the work without restriction under copyright or database law.", + "terms" => [], + "url" => url('/site/kb/licenses') + ], + 11 => [ + "id" => 11, + "title" => "CC BY", + "name" => "Attribution", + "description" => "This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, so long as attribution is given to the creator. The license allows for commercial use.", + "terms" => [ + "Credit must be given to the creator", + ], + "url" => "https://creativecommons.org/licenses/by/4.0/" + ], + 12 => [ + "id" => 12, + "title" => "CC BY-SA", + "name" => "Attribution-ShareAlike", + "description" => "This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, so long as attribution is given to the creator. The license allows for commercial use. If you remix, adapt, or build upon the material, you must license the modified material under identical terms.", + "terms" => [ + "Credit must be given to the creator", + "Adaptations must be shared under the same terms" + ], + "url" => "https://creativecommons.org/licenses/by-sa/4.0/" + ], + 13 => [ + "id" => 13, + "title" => "CC BY-NC", + "name" => "Attribution-NonCommercial", + "description" => "This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format for noncommercial purposes only, and only so long as attribution is given to the creator.", + "terms" => [ + "Credit must be given to the creator", + "Only noncommercial uses of the work are permitted" + ], + "url" => "https://creativecommons.org/licenses/by-nc/4.0/" + ], + 14 => [ + "id" => 14, + "title" => "CC BY-NC-SA", + "name" => "Attribution-NonCommercial-ShareAlike", + "description" => "This license allows reusers to distribute, remix, adapt, and build upon the material in any medium or format for noncommercial purposes only, and only so long as attribution is given to the creator. If you remix, adapt, or build upon the material, you must license the modified material under identical terms.", + "terms" => [ + "Credit must be given to the creator", + "Only noncommercial uses of the work are permitted", + "Adaptations must be shared under the same terms" + ], + "url" => "https://creativecommons.org/licenses/by-nc-sa/4.0/" + ], + 15 => [ + "id" => 15, + "title" => "CC BY-ND", + "name" => "Attribution-NoDerivs", + "description" => "This license allows reusers to copy and distribute the material in any medium or format in unadapted form only, and only so long as attribution is given to the creator. The license allows for commercial use.", + "terms" => [ + "Credit must be given to the creator", + "No derivatives or adaptations of the work are permitted" + ], + "url" => "https://creativecommons.org/licenses/by-nd/4.0/" + ], + 16 => [ + "id" => 16, + "title" => "CC BY-NC-ND", + "name" => "Attribution-NonCommercial-NoDerivs", + "description" => "This license allows reusers to copy and distribute the material in any medium or format in unadapted form only, for noncommercial purposes only, and only so long as attribution is given to the creator.", + "terms" => [ + "Credit must be given to the creator", + "Only noncommercial uses of the work are permitted", + "No derivatives or adaptations of the work are permitted" + ], + "url" => "https://creativecommons.org/licenses/by-nc-nd/4.0/" + ] + ]; + } + + public static function keys() + { + return array_keys(self::get()); + } + + public static function getId($index) + { + return self::get()[$index]['id']; + } + + public static function names() + { + return collect(self::get()) + ->map(function($v) { + return $v['title']; + }) + ->values() + ->toArray(); + } +}