Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadil-K committed Oct 29, 2024
1 parent a866981 commit 73d997d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
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
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 73d997d

Please sign in to comment.