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

73 lines
2.0 KiB
PHP

<?php
namespace RomhackPlazaFS\Endpoints;
use RomhackPlazaFS\Library\Data;
use RomhackPlazaFS\Library\Log;
use RomhackPlazaFS\RomhackPlazaFS;
defined( 'ROMHACKPLAZA_FS' ) || exit;
class Markasprivate extends Abstract_Endpoint {
private int $post_id;
private string $custom_post_type;
private string $file_name;
protected function private_endpoint(): bool
{
return true;
}
protected function require_token(): bool
{
return true;
}
protected function get_post_params(): void {
$this->post_id = $this->swiffer_post( "post_id", "int" );
if( $this->post_id < 1 )
RomhackPlazaFS::invalid_parameter_stop( "post_id", "POST" );
$this->custom_post_type = $this->swiffer_post( "post_type", "string" );
if( $this->custom_post_type === "" )
RomhackPlazaFS::invalid_parameter_stop( "post_type", "POST" );
$this->file_name = $this->swiffer_post( "filename", "filename" );
if( $this->file_name === "" )
RomhackPlazaFS::invalid_parameter_stop( "filename", "POST" );
}
protected function process(): void {
$data = Data::setup(
$this->custom_post_type,
$this->post_id,
$this->file_name
);
if( !$data->file_exists() )
RomhackPlazaFS::fatal_stop( 404, "File not found." );
$new_data = Data::setup(
$this->custom_post_type,
$this->post_id,
$this->file_name,
Data::F_PRIVATE_FILE
);
if( $new_data->file_exists() )
RomhackPlazaFS::fatal_stop( 500, "File already exists. Can't replace. Please delete private file before." );
new Log( __class__, "WP Id=" . $this->token_info['user_id'] ,$this->file_name, $this->post_id, $this->custom_post_type );
if( $data->change_data_location( $new_data ) )
RomhackPlazaFS::success_response( [ 'status' => Data::STATUS_PRIVATE ] );
RomhackPlazaFS::fatal_stop( 500, "Error during file marking" );
}
}