Merge branch 'master' into feature/19-user-profile-screen

This commit is contained in:
Andy Heathershaw 2018-08-03 12:28:32 +01:00
commit 843f284570
5 changed files with 136 additions and 40 deletions

View File

@ -15,6 +15,7 @@ use App\Http\Requests\SaveSettingsRequest;
use App\Label;
use App\Mail\TestMailConfig;
use App\Photo;
use App\Services\GiteaService;
use App\Services\GithubService;
use App\Services\PhotoService;
use App\Storage;
@ -46,18 +47,18 @@ class DefaultController extends Controller
{
try
{
$githubService = new GithubService();
$releaseInfo = $githubService->checkForLatestRelease();
$giteaService = new GiteaService();
$releaseInfo = $giteaService->checkForLatestRelease();
// Convert the publish date so we can re-format it with the user's settings
$publishDate = \DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $releaseInfo->published_at);
$publishDate = \DateTime::createFromFormat('Y-m-d\TH:i:sP', $releaseInfo->published_at);
// HTML-ify the body text
$body = nl2br($releaseInfo->body);
$body = preg_replace('/\*\*(.+)\*\*/', '<b>$1</b>', $body);
// Remove the "v" from the release name
$version = substr($releaseInfo->name, 1);
$version = substr($releaseInfo->tag_name, 1);
// Determine if we can upgrade
$canUpgrade = version_compare($version, config('app.version')) > 0;

View File

@ -0,0 +1,112 @@
<?php
namespace App\Services;
class GiteaService
{
private $cacheFile = null;
private $config = [];
public function __construct()
{
$this->config = config('services.gitea');
$this->cacheFile = storage_path('app/gitea_cache.txt');
}
public function checkForLatestRelease()
{
$cacheData = null;
if ($this->doesCacheExist())
{
// Get the etag from the cache
$cacheData = $this->getCacheData();
}
else
{
// Lookup and store the version information
$statusCode = -1;
$result = $this->getLatestReleaseFromGitea($statusCode);
if ($statusCode == 200)
{
$releases = json_decode($result[1]);
$latestRelease = null;
foreach ($releases as $release)
{
if (is_null($latestRelease) || version_compare($release->tag_name, $latestRelease->tag_name) > 0)
{
$latestRelease = $release;
}
}
$cacheData = $this->setCacheData($latestRelease);
}
}
// GitHub compatibility
$cacheData->html_url = sprintf($this->config['releases_url'], $this->config['repo_owner'], $this->config['repo_name']);
return $cacheData;
}
private function doesCacheExist()
{
$exists = file_exists($this->cacheFile);
if ($exists)
{
// Check modified time on the file
$stat = stat($this->cacheFile);
$diff = time() - $stat['mtime'];
if ($diff > $this->config['cache_time_seconds'])
{
$exists = false;
}
}
return $exists;
}
private function getCacheData()
{
return json_decode(file_get_contents($this->cacheFile));
}
private function getLatestReleaseFromGitea(&$statusCode)
{
$httpHeaders = [
sprintf('User-Agent: aheathershaw/blue-twilight (v%s)', config('app.version'))
];
if (isset($this->config['api_key']) && !empty($this->config['api_key']))
{
$httpHeaders[] = sprintf('Authorization: %s', $this->config['api_key']);
}
$apiUrl = sprintf('%s/repos/%s/%s/releases', $this->config['api_url'], $this->config['repo_owner'], $this->config['repo_name']);
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if ($result === false)
{
throw new \Exception(sprintf('Error from Gitea: %s', curl_error($ch)));
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return explode("\r\n\r\n", $result, 2);
}
private function setCacheData($data)
{
file_put_contents($this->cacheFile, json_encode(get_object_vars($data)));
return $data;
}
}

View File

@ -14,33 +14,15 @@ return [
|
*/
'github' => [
'latest_release_url' => 'https://api.github.com/repos/andysh-uk/blue-twilight/releases/latest'
'gitea' => [
'api_url' => 'https://apps.andysh.uk/api/v1',
'cache_time_seconds' => 3600,
'releases_url' => 'https://apps.andysh.uk/%s/%s/releases',
'repo_name' => 'blue-twilight',
'repo_owner' => 'aheathershaw'
],
'recaptcha' => [
'verify_url' => 'https://www.google.com/recaptcha/api/siteverify'
]
/*'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'sparkpost' => [
'secret' => env('SPARKPOST_SECRET'),
],
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],*/
];

View File

@ -1,6 +1,7 @@
# Contributing to Blue Twilight
Blue Twilight is an open-source project. The source code is freely available for you to use and modify as appropriate to your needs.
If you would like to contribute your changes back to the project, please fork the repository and submit a pull request on Github.
Blue Twilight is an open-source project. The source code is freely available for anyone to use and modify as appropriate to their needs.
Please feel free to contact me any time through [the contact form](https://www.andyheathershaw.uk/contact) on my website.
If you wish to contribute your changes back to the project, I will glady provide you with a Git repository stored on my server for your own fork of the Blue Twilight repository.
Please [follow the instructions here](https://andysh.uk/software/blue-twilight-php-photo-gallery/contributing/) and get developing!

View File

@ -4,7 +4,7 @@ Blue Twilight is a web-based application to store, manage and display collection
It takes advantage of modern frameworks (Laravel, Bootstrap 4, VueJS) as well as new approaches to photo management - such as storing photos on cloud storage providers (Memstore, Rackspace, Amazon S3) and serving the images directly from the respective CDNs.
You can see Blue Twilight in action on my own photo gallery - the reason I wrote Blue Twilight - at: https://photos.andyheathershaw.uk
You can see Blue Twilight in action on my own photo gallery - the reason I wrote Blue Twilight - at: [photos.andysh.uk](https://photos.andysh.uk)
## Version 2 Branch (2.0, 2.1, etc.)
@ -12,11 +12,11 @@ Version 2 is the first version I have released as open-source. The previous vers
This is a major update that includes 2 key new features: fine-grained security controls, and nested albums. It also updates the default template to Bootstrap v4 and VueJS (replacing KnockoutJS.)
With the launch of version 2.0.0, this has now been officially released - see the [Releases](https://github.com/pandy06269/blue-twilight/releases) page for the latest version.
With the launch of version 2.0.0, this has now been officially released - see the [Releases](https://apps.andysh.uk/aheathershaw/blue-twilight/releases) page for the latest version.
## Demo System
See Blue Twilight in action using the demo system. Full details are [available here](https://www.andyheathershaw.uk/software/blue-twilight-php-photo-gallery/demo/).
See Blue Twilight in action using the demo system. Full details are [available here](https://andysh.uk/software/blue-twilight-php-photo-gallery/demo/).
The link to the demo system is: http://demo.showmy.photos. Login with:
@ -25,17 +25,17 @@ The link to the demo system is: http://demo.showmy.photos. Login with:
## Useful Links
* [Blue Twilight website](https://www.andyheathershaw.uk/software/blue-twilight-php-photo-gallery/)
* [User Manual](https://www.andyheathershaw.uk/software/blue-twilight-php-photo-gallery/manual/)
* [Installation Guide](https://www.andyheathershaw.uk/software/blue-twilight-php-photo-gallery/manual/installation/)
* [Issues/Tasks](https://github.com/pandy06269/blue-twilight/issues)
* [Roadmap](https://github.com/pandy06269/blue-twilight/milestones)
* [Blue Twilight website](https://andysh.uk/software/blue-twilight-php-photo-gallery/)
* [User Manual](https://andysh.uk/software/blue-twilight-php-photo-gallery/manual/)
* [Installation Guide](https://andysh.uk/software/blue-twilight-php-photo-gallery/manual/installation/)
* [Issues/Tasks](https://apps.andysh.uk/aheathershaw/blue-twilight/issues)
* [Roadmap](https://apps.andysh.uk/aheathershaw/blue-twilight/milestones)
## Need Help?
I'd love to get you up and running. If you need assistance installing the Blue Twilight PHP photo gallery, or would like to me to do it for you, please get in touch using the contact form located at:
[www.andyheathershaw.uk/contact](https://www.andyheathershaw.uk/contact)
[andysh.uk/contact](https://andysh.uk/contact)
## More Apps by Andy