mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-06 02:33:48 +00:00
added it_get_public_thumbnail test
This commit is contained in:
@@ -147,7 +147,7 @@ class FileAccessController extends Controller
|
||||
$shared = get_shared($token);
|
||||
|
||||
// Abort if shared is protected
|
||||
if ((int) $shared->is_protected) {
|
||||
if ((int)$shared->is_protected) {
|
||||
abort(403, "Sorry, you don't have permission");
|
||||
}
|
||||
|
||||
@@ -160,9 +160,10 @@ class FileAccessController extends Controller
|
||||
$this->check_file_access($shared, $file);
|
||||
|
||||
// Store user download size
|
||||
User::find($shared->user_id)
|
||||
$shared
|
||||
->user
|
||||
->record_download(
|
||||
(int) $file->getRawOriginal('filesize')
|
||||
(int)$file->getRawOriginal('filesize')
|
||||
);
|
||||
|
||||
return $this->download_file($file, $shared->user_id);
|
||||
@@ -211,14 +212,21 @@ class FileAccessController extends Controller
|
||||
}
|
||||
|
||||
// Get file record
|
||||
$file = File::where('user_id', $shared->user_id)
|
||||
$file = UserFile::where('user_id', $shared->user_id)
|
||||
->where('thumbnail', $filename)
|
||||
->firstOrFail();
|
||||
|
||||
// Check file access
|
||||
$this->check_file_access($shared, $file);
|
||||
|
||||
return $this->thumbnail_file($file);
|
||||
// Store user download size
|
||||
$shared
|
||||
->user
|
||||
->record_download(
|
||||
(int)$file->getRawOriginal('filesize')
|
||||
);
|
||||
|
||||
return $this->thumbnail_file($file, $shared->user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,11 @@ class Share extends Model
|
||||
return url('/shared', ['token' => $this->attributes['token']]);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Model events
|
||||
*/
|
||||
|
||||
@@ -75,6 +75,48 @@ class ShareContentAccessTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_public_thumbnail()
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
$this->setup->create_directories();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
$thumbnail = UploadedFile::fake()
|
||||
->image(Str::random() . '-fake-thumbnail.jpg');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $thumbnail, $thumbnail->name);
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'thumbnail' => $thumbnail->name,
|
||||
'name' => 'fake-thumbnail.jpg',
|
||||
]);
|
||||
|
||||
$share = Share::factory(Share::class)
|
||||
->create([
|
||||
'item_id' => $file->id,
|
||||
'user_id' => $user->id,
|
||||
'type' => 'file',
|
||||
'is_protected' => false,
|
||||
]);
|
||||
|
||||
// Get shared file
|
||||
$this->get("/thumbnail/$thumbnail->name/public/$share->token")
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertDatabaseMissing('traffic', [
|
||||
'user_id' => $user->id,
|
||||
'download' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user