Skip to content

Commit

Permalink
Merge pull request #32 from hyvor/laravel-app
Browse files Browse the repository at this point in the history
Laravel App Fixes
  • Loading branch information
Nadil-K authored Oct 29, 2024
2 parents 344924a + 73d997d commit a600125
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 89 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/vendor/
.idea
app/
.idea
59 changes: 2 additions & 57 deletions app/.env.example
Original file line number Diff line number Diff line change
@@ -1,66 +1,11 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

PHP_CLI_SERVER_WORKERS=4

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=

SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database
APP_URL=http://127.0.0.1:7272

CACHE_STORE=database
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"
REDIS_PORT=6379
32 changes: 18 additions & 14 deletions app/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ public function init(Request $request): JsonResponse
{
$request->validate([
'url' => 'required|url',
'method' => 'nullable|string|in:link,embed,link_embed',
'method' => 'nullable|string|in:embed,link',
'embedMetaFallback' => 'nullable|boolean',
]);

$url = (string) $request->string('url');
$method = $request->string('method', 'link');
$method = UnfoldMethod::from($method);
$embedMetaFallback = $request->boolean('embedMetaFallback');

$method = (string) $request->string('method', 'link');
try {
$response = Unfold::unfold(
$url,
$method,
new UnfoldConfig(
$embedMetaFallback,
app()->bound('httpClient') ? app('httpClient') : null
)
);
if ($method === 'embed') {
$response = Unfold::embed(
$url,
new UnfoldConfig(
app()->bound('httpClient') ? app('httpClient') : null
)
);
} else {
$response = Unfold::link(
$url,
new UnfoldConfig(
app()->bound('httpClient') ? app('httpClient') : null
)
);
}
} catch (UnfoldException $e) {
return response()->json([
'error' => $e->getMessage(),
Expand All @@ -52,7 +56,7 @@ public function iframe(Request $request): string
$url = (string) $request->string('url');

try {
$data = Unfold::unfold($url, UnfoldMethod::EMBED);
$data = Unfold::embed($url);
} catch (UnfoldException) {
return 'This URL cannot be embedded.';
}
Expand Down
2 changes: 1 addition & 1 deletion app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
|
*/

'name' => env('APP_NAME', 'Laravel'),
'name' => env('APP_NAME', 'Unfold'),

/*
|--------------------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions app/tests/Feature/IframeApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace Tests\Feature;

it('returns embed html', function () {
$response = $this->getJson('/iframe?'.http_build_query([
'url' => 'https://www.youtube.com/watch?v=9bZkp7q19f0',
]));

$response->assertStatus(200);
$html = $response->getContent();

expect($html)->toContain('<html>')
->and($html)->toContain('<body style="margin:0;overflow:hidden">')
->and($html)->toContain('<div style="position:relative;left:0;width:100%;height:0;padding-bottom:56.25%;"><iframe')
->and($html)->toContain('src="https://www.youtube.com/embed/9bZkp7q19f0"')
->and($html)->toContain('style="position: absolute;top:0;left:0;width:100%;height:100%;border:0;"')
->and($html)->toContain('allow="fullscreen;accelerometer;clipboard-write;encrypted-media;gyroscope;picture-in-picture;web-share;"></iframe>')
->and($html)->toContain('const height = document.documentElement.scrollHeight;')
->and($html)->toContain('function sendDelayedHeight() {')
->and($html)->toContain('const mutation = new window.MutationObserver(sendDelayedHeight);')
->and($html)->toContain(`document.addEventListener('resize', sendDelayedHeight);`);
});

it('returns error for invalid url', function () {
$response = $this->getJson('/iframe?'.http_build_query([
'url' => 'https://invalid.url',
]));
$response->assertStatus(200);
$response->assertSee('This URL cannot be embedded.');
});
15 changes: 0 additions & 15 deletions app/tests/Feature/UnfoldApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
$response->assertStatus(200);
$response->assertJsonFragment([
'version' => '1.0',
'method' => 'link',
'url' => 'https://nadil.me/google-cloud-platform',
'embed' => null,
'title' => 'Google Cloud Platform (GCP): Setting up a GPU-Based Virtual Machine (VM) with Jupyter Notebook for LLMs',
'description' => 'A descriptive guide on how to setup a gpu based vm in google cloud platform',
'authors' => [
Expand Down Expand Up @@ -73,20 +71,7 @@
$response->assertStatus(200);
$response->assertJsonFragment([
'version' => '1.0',
'method' => 'embed',
'url' => 'https://www.youtube.com/watch?v=Bag1gUxuU0g',
'embed' => '<div style="position:relative;left:0;width:100%;height:0;padding-bottom:56.25%;"><iframe src="https://www.youtube.com/embed/Bag1gUxuU0g" style="position: absolute;top:0;left:0;width:100%;height:100%;border:0;" allow="fullscreen;accelerometer;clipboard-write;encrypted-media;gyroscope;picture-in-picture;web-share;"></iframe></div>',
'title' => null,
'description' => null,
'authors' => [],
'tags' => [],
'siteName' => null,
'siteUrl' => null,
'canonicalUrl' => null,
'publishedTime' => null,
'modifiedTime' => null,
'thumbnailUrl' => null,
'iconUrl' => null,
'locale' => null,
]);
});

0 comments on commit a600125

Please sign in to comment.