join('documents as d','d.id','=','r.document_id')->where('d.media_type','image/png')->where('r.published',true)->first(['d.storage_key','d.sha256','r.id']); if(!$r)throw new RuntimeException('Existing QA image required'); $root=dirname(__DIR__,2).'/storage/app/private/';$from=realpath($root.$r->storage_key);$base=realpath($root); if(!$from||!str_starts_with(strtolower($from),strtolower($base.DIRECTORY_SEPARATOR))||hash_file('sha256',$from)!==trim($r->sha256))throw new RuntimeException('Read-only image source integrity'); $to=Illuminate\Support\Facades\Storage::disk('local')->path($r->storage_key);if(!is_dir(dirname($to)))mkdir(dirname($to),0700,true);copy($from,$to); echo json_encode(['id'=>$r->id,'sha256'=>trim($r->sha256),'active_source_read_only'=>true]);