Przeglądaj źródła

Add S3 + Stories

Daniel Supernault 5 lat temu
rodzic
commit
7faa9d8e61

+ 5 - 0
app/Profile.php

@@ -303,4 +303,9 @@ class Profile extends Model
             ->whereFollowingId($this->id)
             ->exists();
     }
+
+    public function stories()
+    {
+        return $this->hasMany(Story::class);
+    }
 }

+ 0 - 1
app/Providers/AuthServiceProvider.php

@@ -36,7 +36,6 @@ class AuthServiceProvider extends ServiceProvider
                 'read',
                 'write',
                 'follow',
-                'push'
             ]);
 
             Passport::tokensCan([

+ 2 - 6
app/Status.php

@@ -131,13 +131,9 @@ class Status extends Model
         $media = $this->firstMedia();
         $path = $media->media_path;
         $hash = is_null($media->processed_at) ? md5('unprocessed') : md5($media->created_at);
-        if(config('pixelfed.cloud_storage') == true) {
-            $url = Storage::disk(config('filesystems.cloud'))->url($path)."?v={$hash}";
-        } else {
-            $url = Storage::url($path)."?v={$hash}";
-        }
+        $url = $media->cdn_url ? $media->cdn_url . "?v={$hash}" : url(Storage::url($path)."?v={$hash}");
 
-        return url($url);
+        return $url;
     }
 
     public function likes()

+ 5 - 12
app/Story.php

@@ -24,6 +24,8 @@ class Story extends Model
      */
     protected $dates = ['published_at', 'expires_at'];
 
+    protected $fillable = ['profile_id'];
+
 	protected $visible = ['id'];
 
 	public function profile()
@@ -31,16 +33,6 @@ class Story extends Model
 		return $this->belongsTo(Profile::class);
 	}
 
-	public function items()
-	{
-		return $this->hasMany(StoryItem::class);
-	}
-
-	public function reactions()
-	{
-		return $this->hasMany(StoryReaction::class);
-	}
-
 	public function views()
 	{
 		return $this->hasMany(StoryView::class);
@@ -48,7 +40,8 @@ class Story extends Model
 
 	public function seen($pid = false)
 	{
-		$id = $pid ?? Auth::user()->profile->id;
-		return $this->views()->whereProfileId($id)->exists();
+		return StoryView::whereStoryId($this->id)
+			->whereProfileId(Auth::user()->profile->id)
+			->exists();
 	}
 }

+ 63 - 0
database/migrations/2019_12_25_042317_update_stories_table.php

@@ -0,0 +1,63 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class UpdateStoriesTable extends Migration
+{
+    public function __construct()
+    {
+        DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
+    }
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::dropIfExists('stories');
+        Schema::dropIfExists('story_items');
+        Schema::dropIfExists('story_reactions');
+        Schema::dropIfExists('story_views');
+
+        Schema::create('stories', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->bigInteger('profile_id')->unsigned()->index();
+            $table->string('type')->nullable();
+            $table->unsignedInteger('size')->nullable();
+            $table->string('mime')->nullable();
+            $table->smallInteger('duration')->unsigned();
+            $table->string('path')->nullable();
+            $table->string('cdn_url')->nullable();
+            $table->boolean('public')->default(false)->index();
+            $table->boolean('local')->default(false)->index();
+            $table->unsignedInteger('view_count')->nullable();
+            $table->unsignedInteger('comment_count')->nullable();
+            $table->json('story')->nullable();
+            $table->unique(['profile_id', 'path']);
+            $table->timestamp('expires_at')->index();
+            $table->timestamps();
+        });
+
+        Schema::create('story_views', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->bigInteger('story_id')->unsigned()->index();
+            $table->bigInteger('profile_id')->unsigned()->index();
+            $table->unique(['profile_id', 'story_id']);
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('stories');
+        Schema::dropIfExists('story_views');
+    }
+}

+ 4 - 0
resources/assets/js/story-compose.js

@@ -0,0 +1,4 @@
+Vue.component(
+    'story-compose',
+    require('./components/StoryCompose.vue').default
+);

+ 5 - 0
resources/assets/js/timeline.js

@@ -41,4 +41,9 @@ Vue.component(
 Vue.component(
     'announcements-card',
     require('./components/AnnouncementsCard.vue').default
+);
+
+Vue.component(
+    'story-component',
+    require('./components/StoryTimelineComponent.vue').default
 );