Files
Romhack-Plaza---File-Server/src/Endpoints/Getfilesize.php
2026-01-30 11:03:44 +01:00

76 lines
2.2 KiB
PHP

<?php
namespace RomhackPlazaFS\Endpoints;
use RomhackPlazaFS\Library\Data;
use RomhackPlazaFS\Library\Log;
use RomhackPlazaFS\RomhackPlazaFS;
defined( 'ROMHACKPLAZA_FS' ) || exit;
class Getfilesize extends Abstract_Endpoint {
private int $post_id;
private string $custom_post_type;
private string $file_name;
private string $is_private;
private string $is_archived;
protected function private_endpoint(): bool
{
return true;
}
protected function require_token(): bool
{
return false;
}
protected function get_post_params(): void {
$this->post_id = $this->swiffer_get( "entry_id", "int" );
if( $this->post_id < 1 )
RomhackPlazaFS::invalid_parameter_stop( "entry_id", "GET" );
$this->custom_post_type = $this->swiffer_get( "post_type", "string" );
if( $this->custom_post_type === "" )
RomhackPlazaFS::invalid_parameter_stop( "post_type", "GET" );
$this->file_name = $this->swiffer_get( "filename", "filename" );
if( $this->file_name === "" )
RomhackPlazaFS::invalid_parameter_stop( "filename", "GET" );
$this->is_private = $this->swiffer_get( "is_private", "string" );
if( $this->is_private !== "no" && $this->is_private !== "yes" )
$this->is_private = "no";
$this->is_archived = $this->swiffer_get( "is_archived", "string" );
if( $this->is_archived !== "no" && $this->is_archived !== "yes" )
$this->is_archived = "no";
}
protected function process(): void {
$flags = 0;
if( $this->is_private === "yes" )
$flags |= Data::F_PRIVATE_FILE;
else if( $this->is_archived === "yes" )
$flags |= Data::F_ARCHIVED_FILE;
$data = Data::setup(
$this->custom_post_type,
$this->post_id,
$this->file_name,
$flags
);
if( !$data->file_exists() )
RomhackPlazaFS::fatal_stop( 404, "File not found." );
new Log( __class__,$this->file_name, $this->post_id, $this->custom_post_type );
RomhackPlazaFS::success_response( [ 'size' => $data->size() ] );
}
}