Compare commits

..

4 Commits

8 changed files with 117 additions and 6 deletions

59
.env Normal file
View File

@ -0,0 +1,59 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

View File

@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class ClearDownloads extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:clear-downloads';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
$this->info("Clearing download directory: " . env('PATH_TO_DOWNLOAD'));
$directory = new Filesystem();
$files = $directory->files(env('PATH_TO_DOWNLOAD'), false);
$counter = 0;
foreach ($files as $file){
if ($file->getFilename() !== '.gitignore'){
$this->info("rm " . $file->getRealPath());
unlink($file->getRealPath());
$counter++;
}
}
$this->info("Deleted " . $counter . " file(s)");
}
}

View File

@ -13,6 +13,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->command('app:clear-downloads')->daily();
}
/**

View File

@ -11,6 +11,6 @@ class DownloadController extends Controller
$headers = [
'Content-Type' => 'video/mp4',
];
return response()->download($file_path, $file_name, $headers);
return response()->download($file_path, $file_name, $headers)->deleteFileAfterSend();
}
}

View File

@ -30,8 +30,11 @@ class YoutubeDownloadController extends Controller
return response(json_encode($response));
} else {
$videotitle = $video->getFile()->getFilename();
$thumbnails = $video->getThumbnails();
$thumbnail = $thumbnails[0]?->getUrl();
$response = new \stdClass();
$response->link = $videotitle;
$response->thumbnail = $thumbnail;
return response(json_encode($response));
}
}

View File

@ -46,7 +46,7 @@ export default {
this.downloadAvailable = false;
this.error = false;
this.fetching = true;
axios.get(`/download_api?videourl=${this.url}`).then((responce)=>{
axios.get(`/api/v1/video/download?videourl=${this.url}`).then((responce)=>{
this.fetching = false;
if (responce.data.error){
this.error = true;
@ -55,7 +55,7 @@ export default {
console.log(responce.data.error);
} else if (responce.data.link){
this.downloadAvailable = true;
this.downloadLink = `/download/${responce.data.link}`;
this.downloadLink = `/api/v1/file/download/${responce.data.link}`;
}
}).catch((error)=>{
this.fetching = false;

View File

@ -17,3 +17,12 @@ use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::group(['prefix' => 'v1'], function () {
Route::group(['prefix' => 'video'], function () {
Route::get('/download', 'App\Http\Controllers\YoutubeDownloadController@index');
});
Route::group(['prefix' => 'file'], function () {
Route::get('/download/{file}', 'App\Http\Controllers\DownloadController@download')->name('download');
});
});

View File

@ -16,6 +16,3 @@ use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::get('/download_api', 'App\Http\Controllers\YoutubeDownloadController@index');
Route::get('/download/{file}', 'App\Http\Controllers\DownloadController@download')->name('download');