Skip to content

Commit

Permalink
More permanent fix for #584 (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennettscience authored May 28, 2020
1 parent c896e3d commit 403efed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
38 changes: 22 additions & 16 deletions app/Http/Controllers/RSSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Http\Controllers;

use App;
use App\Configs;
use App\ModelFunctions\AlbumFunctions;
use App\ModelFunctions\SymLinkFunctions;
Expand All @@ -13,7 +12,6 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Spatie\Feed\FeedItem;
use Storage;

class RSSController extends Controller
{
Expand All @@ -37,6 +35,18 @@ public function __construct(AlbumFunctions $albumFunctions, SymLinkFunctions $sy
$this->symLinkFunctions = $symLinkFunctions;
}

public function make_enclosure($photo)
{
$enclosure = new \stdClass();

$path = public_path($photo['url']);
$enclosure->length = File::size($path);
$enclosure->mime_type = File::mimeType($path);
$enclosure->url = url('/' . $photo['url']);

return $enclosure;
}

/**
* @return Collection
*/
Expand All @@ -48,10 +58,12 @@ public function getRSS()

$photos = Photo::with('album', 'owner')
->where('created_at', '>=', Carbon::now()->subDays(intval(Configs::get_value('rss_recent_days', '7')))
->toDateTimeString())
->toDateTimeString())
->where(function ($q) {
$q->whereIn('album_id',
$this->albumFunctions->getPublicAlbums())
$q->whereIn(
'album_id',
$this->albumFunctions->getPublicAlbums()
)
->orWhere('public', '=', '1');
})
->limit(Configs::get_Value('rss_max_items', '100'))
Expand All @@ -76,25 +88,19 @@ public function getRSS()

$photo['url'] = $photo['url'] ?: $photo['medium2x'] ?: $photo['medium'];
// TODO: this will need to be fixed for s3 and when the upload folder is NOT the Lychee folder.
if (App::runningUnitTests()) {
$path = Storage::path('../' . $photo['url']);
} else {
$path = Storage::path($photo['url']);
}
$length = File::size($path);
$mime_type = File::mimeType($path);
$enclosure = $this->make_enclosure($photo);

return FeedItem::create([
'id' => url('/' . $id),
'title' => $photo_model->title,
'summary' => $photo_model->description,
'updated' => $photo_model->created_at,
'link' => $photo['url'],
'enclosureLength' => $length,
'enclosureMime' => $mime_type,
'author' => $photo_model->owner->username, ]);
'enclosure' => $enclosure,
'author' => $photo_model->owner->username,
]);
});

return $photos;
}
}
}
4 changes: 3 additions & 1 deletion resources/views/vendor/feed/rss.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<description><![CDATA[{!! $item->summary !!}]]></description>
<author><![CDATA[{{ $item->author }}]]></author>
<guid>{{ url($item->id) }}</guid>
<enclosure url="{{ url($item->link)}}" type="{{ $item->enclosureMime }}" length="{{ $item->enclosureLength }}" />
@if(isset($item->enclosure))
<enclosure url="{{ $item->enclosure->url }}" length="{{ $item->enclosure->length }}" type="{{ $item->enclosure->mime_type }}" />
@endif
<pubDate>{{ $item->updated->toRssString() }}</pubDate>
</item>
@endforeach
Expand Down

0 comments on commit 403efed

Please sign in to comment.