Files
pilot-sdk/src/Entity/Action.php
2025-10-01 10:46:20 +02:00

79 lines
1.7 KiB
PHP

<?php
namespace Bluesquare\Pilot\Entity;
use Illuminate\Support\Str;
abstract class Action extends Entity
{
public function action(
$type = 'info',
$title = null,
$message = null,
$button = null,
$url = null,
$files = [],
) {
return [
'json' => [
'type' => 'action',
'action' => compact('type', 'title', 'message', 'button', 'url', 'files'),
],
];
}
public function file(
$contents,
$name = '',
$type = ''
) {
return [
'file' => compact('contents', 'name', 'type'),
];
}
public function iframe($url, $expires = 240)
{
$key = 'pilot_action_' . Str::random(10);
$token = Str::random(40);
cache()->add($key, $token, now()->addMinutes($expires));
$url = $url . (str_contains($url, '?') ? '&' : '?') . "pilot_token=$key|$token";
return [
'json' => [
'type' => 'iframe',
'url' => $url,
],
];
}
public function link($url, $expires = 5)
{
$key = 'pilot_action_' . Str::random(10);
$token = Str::random(40);
cache()->add($key, $token, now()->addMinutes($expires));
$url = $url . (str_contains($url, '?') ? '&' : '?') . "pilot_token=$key|$token";
return [
'json' => [
'type' => 'link',
'url' => $url,
],
];
}
public function error($message)
{
return [
'json' => [
'type' => 'error',
'error' => $message,
],
];
}
}