- Inject LoggerInterface across WebhookController, TalkService, and ImageCleanup - Replace TalkService.getAvailableTalkRooms() OCS API calls with direct database queries - Add getBaseUrl() helper to resolve localhost/SSRF constraints for internal API calls - Update buildRichObject() to generate public link shares for file attachments - Add saveBotPassword, debug, and debugTables endpoints to WebhookController - Separate frontend assets (JS/CSS) from adminSettings template - Add composer.json and autoload files for PSR-4 autoloading - Update Admin settings to use TemplateResponse and register app icons
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace OCA\NCdiscordhook\Cron;
|
|
|
|
use OCA\NCdiscordhook\Service\TalkService;
|
|
use OCP\BackgroundJob\IJob;
|
|
use OCP\Files\IRootFolder;
|
|
use OCP\IConfig;
|
|
use OCP\IUserManager;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ImageCleanup implements IJob {
|
|
private TalkService $talkService;
|
|
private IRootFolder $rootFolder;
|
|
private IUserManager $userManager;
|
|
private LoggerInterface $logger;
|
|
|
|
public function __construct(
|
|
TalkService $talkService,
|
|
IRootFolder $rootFolder,
|
|
IUserManager $userManager,
|
|
LoggerInterface $logger,
|
|
) {
|
|
$this->talkService = $talkService;
|
|
$this->rootFolder = $rootFolder;
|
|
$this->userManager = $userManager;
|
|
$this->logger = $logger;
|
|
}
|
|
|
|
public function run($argument = null): void {
|
|
// Check if bot user exists
|
|
$bot = $this->userManager->get('talk-bot');
|
|
if (!$bot) {
|
|
return;
|
|
}
|
|
|
|
// Check if images directory exists
|
|
try {
|
|
$userFolder = $this->rootFolder->getUserFolder($bot->getUID());
|
|
$imagesDir = $userFolder->getFolder('NCdiscordhook-images');
|
|
} catch (\Exception $e) {
|
|
return;
|
|
}
|
|
|
|
$count = $this->talkService->purgeOldImages();
|
|
|
|
if ($count > 0) {
|
|
$this->logger->info(
|
|
'NCdiscordhook: purged ' . $count . ' old image files',
|
|
['app' => 'ncdiscordhook'],
|
|
);
|
|
}
|
|
}
|
|
}
|