Skip to content

Commit

Permalink
[Update] Legal API
Browse files Browse the repository at this point in the history
- Added Terms of Use to the OpenAPI spec
- Updated the method of fetching legal docs to match the web version
  • Loading branch information
kiritokatklian committed Apr 27, 2021
1 parent 3e389f7 commit c81af67
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
21 changes: 9 additions & 12 deletions app/Http/Controllers/MiscController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use App\Helpers\JSONResult;
use Carbon\Carbon;
use File;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Storage;
use Markdown;

class MiscController extends Controller
Expand All @@ -21,7 +21,7 @@ class MiscController extends Controller
public function getPrivacyPolicy(): JsonResponse
{
// Get MarkDown content
$privacyPolicyMarkdown = $this->getContentOfFile('resources/static/privacy_policy.md');
$privacyPolicyMarkdown = $this->getContentOfFile('privacy_policy.md');

// Prepare for converting Markdown to HTML
$privacyPolicyText = Markdown::parse($privacyPolicyMarkdown);
Expand All @@ -47,7 +47,7 @@ public function getPrivacyPolicy(): JsonResponse
public function getTermsOfUse(): JsonResponse
{
// Get MarkDown content
$termsOfUseMarkdown = $this->getContentOfFile('resources/static/terms_of_use.md');
$termsOfUseMarkdown = $this->getContentOfFile('terms_of_use.md');

// Prepare for converting Markdown to HTML
$termsOfUseText = Markdown::parse($termsOfUseMarkdown);
Expand All @@ -64,25 +64,22 @@ public function getTermsOfUse(): JsonResponse
}

/**
* Get the content of the given file.
* Get the content of a file with the given name.
*
* @param string $filePath
* @param string $fileName
* @return string
*
* @throws FileNotFoundException
*/
protected function getContentOfFile(string $filePath): string
protected function getContentOfFile(string $fileName): string
{
// Create the file if it does not exist yet
if (!Storage::exists($filePath)) {
Storage::put($filePath, 'Page is empty. Please inform an administrator.');
}
$filePath = resource_path('docs/'. $fileName);

// Get the last update date
$lastUpdateUnix = Carbon::createFromTimestamp(Storage::lastModified($filePath));
$lastUpdateUnix = Carbon::createFromTimestamp(File::lastModified($filePath));
$lastUpdateStr = $lastUpdateUnix->format('F d, Y');

// Attach date and return file content
return str_replace('#UPDATE_DATE#', $lastUpdateStr, Storage::get($filePath));
return str_replace('#UPDATE_DATE#', $lastUpdateStr, File::get($filePath));
}
}
61 changes: 49 additions & 12 deletions public/openapi.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"openapi": "3.0.0",
"openapi": "3.0.3",
"info": {
"description": "Integrate tracking shows with Kurozora content.\n *** \nThe Kurozora API is a web service that lets you access information about the media found in the Kurozora Catalog and the user's personal Kurozora Library. Here's what each one includes:\n- The Kurozora Catalog includes all resources available in Kurozora.\n- The user's Kurozora Library contains only those resources that the user added to their personal library. For example, it contains shows added to their tracking list, and favorites.\n\nUse this service to retrieve information about actors, characters, episodes, genres, shows, studios, threads, users, and the users' library.\nWith proper authorization from the user, you can also create or modify their library, apply ratings to shows, create or modify threads and vote on replies.",
"version": "1.0.8",
"version": "1.2.0",
"title": "Kurozora API",
"termsOfService": "http://swagger.io/terms/",
"termsOfService": "https://swagger.io/terms/",
"contact": {
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"servers": [
Expand Down Expand Up @@ -3376,8 +3376,8 @@
"legal"
],
"operationId": "getPrivacyPolicy",
"summary": "Retrieve latest privacy policy.",
"description": "This endpoint will retrieve the latest privacy policy.",
"summary": "Retrieve latest Privacy Policy.",
"description": "This endpoint will retrieve the latest Privacy Policy.",
"responses": {
"200": {
"$ref": "#/components/responses/GetPrivacyPolicySuccess"
Expand All @@ -3388,6 +3388,24 @@
}
}
},
"/legal/terms-of-use": {
"get": {
"tags": [
"legal"
],
"operationId": "getTermsOfUse",
"summary": "Retrieve latest Terms of Use.",
"description": "This endpoint will retrieve the latest Terms of Use.",
"responses": {
"200": {
"$ref": "#/components/responses/GetTermsOfUseSuccess"
},
"400": {
"$ref": "#/components/responses/JSONError"
}
}
}
},
"/info": {
"get": {
"tags": [
Expand Down Expand Up @@ -5773,7 +5791,7 @@
"logoURL": "https://lorempixel.com/640/480/?85310",
"about": "Eos repellat optio aut explicabo quod. Consequatur sit quasi aliquam sed modi aut. Perspiciatis et perferendis architecto voluptas eos quis iure. Corrupti ea reiciendis et quo sed itaque. Unde ipsa officia et veniam dicta ullam omnis modi. Consequuntur non possimus fugiat quaerat delectus ea. In voluptas dignissimos veniam reprehenderit a. Cum dolores aperiam et nihil. Veniam id rerum commodi quia assumenda at. Et velit iure eos aut. Et est praesentium id fugiat reprehenderit. Sunt dolorem aut ratione ipsam ipsum quo.",
"founded": "1983-09-30",
"websiteURL": "http://rodriguez.com/eos-ut-earum-ut-eum-voluptas-iusto.html"
"websiteURL": "https://rodriguez.com/eos-ut-earum-ut-eum-voluptas-iusto.html"
},
"relationships": {
"shows": {
Expand Down Expand Up @@ -6012,7 +6030,7 @@
"type": "themes",
"attributes": {
"name": "Watermelon",
"screenshot": "http://kurozora-web.test/storage/1/Screenshot.jpeg",
"screenshot": "https://kurozora.app/storage/1/Screenshot.jpeg",
"downloadLink": "/api/v1/themes/1/download"
}
},
Expand All @@ -6021,7 +6039,7 @@
"type": "themes",
"attributes": {
"name": "Blueberry",
"screenshot": "http://kurozora-web.test/storage/2/Screenshot.jpeg",
"screenshot": "https://kurozora.app/storage/2/Screenshot.jpeg",
"downloadLink": "/api/v1/themes/2/download"
}
}
Expand All @@ -6045,8 +6063,8 @@
"href": "/api/v1/themes/1",
"attributes": {
"name": "Tatum Orn",
"screenshot": "http://kurozora-web.test/storage/1/Screenshot.jpeg",
"downloadLink": "http://kurozora-web.test/api/v1/themes/1/download"
"screenshot": "https://kurozora.app/storage/1/Screenshot.jpeg",
"downloadLink": "https://kurozora.app/api/v1/themes/1/download"
}
}
]
Expand All @@ -6066,7 +6084,26 @@
"type": "legal",
"href": "/api/v1/privacy-policy",
"attributes": {
"text": "The privacy policy in HTML format."
"text": "The Privacy Policy in HTML format."
}
}
}
}
}
}
},
"GetTermsOfUseSuccess": {
"description": "Successful GET Terms of Use JSON response",
"content": {
"application/json": {
"schema": {
"type": "object",
"example": {
"data": {
"type": "legal",
"href": "/api/v1/terms-of-use",
"attributes": {
"text": "The Terms of Use in HTML format."
}
}
}
Expand Down

0 comments on commit c81af67

Please sign in to comment.