mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-25 12:37:23 +08:00
add-filesystem-google-drive
This commit is contained in:
@@ -11,6 +11,7 @@ use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Test extends Command
|
||||
{
|
||||
@@ -55,7 +56,9 @@ class Test extends Command
|
||||
// ]);
|
||||
// dd($r);
|
||||
// $rep->assignCronjob();
|
||||
$r = $rep->cronjobCheckout();
|
||||
// $r = $rep->cronjobCheckout();
|
||||
$disk = Storage::disk('google_dirve');
|
||||
$r = $disk->files();
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InviteResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'inviter' => $this->inviter,
|
||||
'invitee' => $this->inviter,
|
||||
'hash' => $this->hash,
|
||||
'time_invited' => $this->time_invited,
|
||||
'valid' => $this->valid,
|
||||
'valid_text' => $this->valid_text,
|
||||
'invitee_register_uid' => $this->invitee_register_uid,
|
||||
'invitee_register_email' => $this->invitee_register_email,
|
||||
'invitee_register_username' => $this->invitee_register_username,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class UserResource extends JsonResource
|
||||
'seedtime_text' => mkprettytime($this->seedtime),
|
||||
'leechtime' => $this->leechtime,
|
||||
'leechtime_text' => mkprettytime($this->leechtime),
|
||||
'invitee_code' => new InviteResource($this->whenLoaded('invitee_code')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -6,7 +6,21 @@ class Invite extends NexusModel
|
||||
{
|
||||
protected $table = 'invites';
|
||||
|
||||
protected $fillable = [
|
||||
'inviter', 'invitee', 'hash', 'time_invited',
|
||||
const VALID_YES = 1;
|
||||
const VALID_NO = 0;
|
||||
|
||||
public static $validInfo = [
|
||||
self::VALID_NO => ['text' => 'No'],
|
||||
self::VALID_YES => ['text' => 'Yes'],
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'inviter', 'invitee', 'hash', 'time_invited', 'valid', 'invitee_register_uid', 'invitee_register_email', 'invitee_register_username'
|
||||
];
|
||||
|
||||
public function getValidTextAttribute()
|
||||
{
|
||||
return self::$validInfo[$this->valid]['text'] ?? '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,4 +134,9 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(Language::class, 'lang');
|
||||
}
|
||||
|
||||
public function invitee_code()
|
||||
{
|
||||
return $this->hasOne(Invite::class, 'invitee_register_uid');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
class GoogleDriveAdapter extends \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter
|
||||
{
|
||||
public function getService()
|
||||
{
|
||||
return $this->service;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class GoogleDriveServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Storage::extend('google_dirve', function($app, $config) {
|
||||
$client = new \Google_Client();
|
||||
$client->setClientId($config['clientId']);
|
||||
$client->setClientSecret($config['clientSecret']);
|
||||
$client->refreshToken($config['refreshToken']);
|
||||
$service = new \Google_Service_Drive($client);
|
||||
|
||||
$options = [];
|
||||
if(isset($config['teamDriveId'])) {
|
||||
$options['teamDriveId'] = $config['teamDriveId'];
|
||||
}
|
||||
|
||||
$adapter = new GoogleDriveAdapter($service, $config['folderId'], $options);
|
||||
|
||||
return new \League\Flysystem\Filesystem($adapter);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class UserRepository extends BaseRepository
|
||||
|
||||
public function getDetail($id)
|
||||
{
|
||||
$user = User::query()->findOrFail($id, User::$commonFields);
|
||||
$user = User::query()->with(['invitee_code'])->findOrFail($id, User::$commonFields);
|
||||
$userResource = new UserResource($user);
|
||||
$baseInfo = $userResource->response()->getData(true)['data'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user