summaryrefslogtreecommitdiff
path: root/classes/pref/feeds.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-11-24 23:31:33 +0300
committerAndrew Dolgov <[email protected]>2022-11-24 23:31:33 +0300
commita30b9bb649d6e10a5d7c2feb73376669cf23ef68 (patch)
tree33716caf2286a0c544a2f053ea07c677aebd5fd4 /classes/pref/feeds.php
parentbe6bc72a742c5fb7f87a4495009ed71ff0fbb8d8 (diff)
rework favicon storage to use DiskCache
Diffstat (limited to 'classes/pref/feeds.php')
-rwxr-xr-xclasses/pref/feeds.php43
1 files changed, 23 insertions, 20 deletions
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index f2e8e12da..067b8225e 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -454,14 +454,15 @@ class Pref_Feeds extends Handler_Protected {
function removeIcon(): void {
$feed_id = (int) $_REQUEST["feed_id"];
- $icon_file = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
+
+ $cache = new DiskCache('feed-icons');
$feed = ORM::for_table('ttrss_feeds')
->where('owner_uid', $_SESSION['uid'])
->find_one($feed_id);
- if ($feed && file_exists($icon_file)) {
- if (unlink($icon_file)) {
+ if ($feed && $cache->exists((string)$feed_id)) {
+ if ($cache->remove((string)$feed_id)) {
$feed->set([
'favicon_avg_color' => null,
'favicon_last_checked' => '1970-01-01',
@@ -486,24 +487,25 @@ class Pref_Feeds extends Handler_Protected {
if ($feed && $tmp_file && move_uploaded_file($_FILES['icon_file']['tmp_name'], $tmp_file)) {
if (filesize($tmp_file) < Config::get(Config::MAX_FAVICON_FILE_SIZE)) {
- $new_filename = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
-
- if (file_exists($new_filename)) unlink($new_filename);
- if (rename($tmp_file, $new_filename)) {
- chmod($new_filename, 0644);
+ $cache = new DiskCache('feed-icons');
- $feed->set([
- 'favicon_avg_color' => null,
- 'favicon_is_custom' => true,
- ]);
+ if ($cache->put((string)$feed_id, file_get_contents($tmp_file))) {
- if ($feed->save()) {
- $rc = self::E_ICON_UPLOAD_SUCCESS;
- }
+ $feed->set([
+ 'favicon_avg_color' => null,
+ 'favicon_is_custom' => true,
+ ]);
- } else {
- $rc = self::E_ICON_RENAME_FAILED;
+ if ($feed->save()) {
+ $rc = self::E_ICON_UPLOAD_SUCCESS;
}
+
+ } else {
+ $rc = self::E_ICON_RENAME_FAILED;
+ }
+
+ @unlink($tmp_file);
+
} else {
$rc = self::E_ICON_FILE_TOO_LARGE;
}
@@ -1186,9 +1188,10 @@ class Pref_Feeds extends Handler_Protected {
$pdo->commit();
- if (file_exists(Config::get(Config::ICONS_DIR) . "/$id.ico")) {
- unlink(Config::get(Config::ICONS_DIR) . "/$id.ico");
- }
+ $favicon_cache = new DiskCache('feed-icons');
+
+ if ($favicon_cache->exists((string)$id))
+ $favicon_cache->remove((string)$id);
} else {
Labels::remove(Labels::feed_to_label_id($id), $owner_uid);