streams/Code/Daemon/Importfile.php

57 lines
1.4 KiB
PHP
Raw Normal View History

2021-12-03 03:01:39 +00:00
<?php
/** @file */
2022-02-16 04:08:28 +00:00
namespace Code\Daemon;
2022-02-16 04:08:28 +00:00
use Code\Lib\Libsync;
use Code\Lib\Channel;
2018-06-01 04:05:09 +00:00
2022-11-27 09:15:28 +00:00
class Importfile implements DaemonInterface
2021-12-03 03:01:39 +00:00
{
2022-11-27 09:15:28 +00:00
public function run(int $argc, array $argv): void
2021-12-03 03:01:39 +00:00
{
2021-12-03 03:01:39 +00:00
logger('Importfile: ' . print_r($argv, true));
2021-12-03 03:01:39 +00:00
if ($argc < 3) {
return;
}
2017-08-23 03:32:02 +00:00
2022-01-25 01:26:12 +00:00
$channel = Channel::from_id($argv[1]);
2021-12-03 03:01:39 +00:00
if (! $channel) {
return;
}
2021-12-03 03:01:39 +00:00
$srcfile = $argv[2];
$folder = (($argc > 3) ? $argv[3] : '');
$dstname = (($argc > 4) ? $argv[4] : '');
2021-12-03 03:01:39 +00:00
$hash = random_string();
2021-12-03 03:01:39 +00:00
$arr = [
'src' => $srcfile,
'filename' => (($dstname) ? $dstname : basename($srcfile)),
'hash' => $hash,
'allow_cid' => $channel['channel_allow_cid'],
'allow_gid' => $channel['channel_allow_gid'],
'deny_cid' => $channel['channel_deny_cid'],
'deny_gid' => $channel['channel_deny_gid'],
'preserve_original' => true,
'replace' => true
];
2021-12-03 03:01:39 +00:00
if ($folder) {
$arr['folder'] = $folder;
}
2021-12-03 03:01:39 +00:00
attach_store($channel, $channel['channel_hash'], 'import', $arr);
2021-12-03 03:01:39 +00:00
$sync = attach_export_data($channel, $hash);
if ($sync) {
2022-11-27 09:15:28 +00:00
Libsync::build_sync_packet($channel['channel_id'], ['file' => [$sync]]);
2021-12-03 03:01:39 +00:00
}
}
}