Skip to content

Commit

Permalink
fix: fix uploadcare (#6942)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 16, 2023
1 parent 7e76619 commit e9c4f9d
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function data(Contact $contact, User $user): array
'quick_fact_template_entries' => self::quickFacts($contact),
'modules' => $firstPage ? self::modules($firstPage, $contact, $user) : [],
'avatar' => [
'uploadcarePublicKey' => config('services.uploadcare.public_key'),
'uploadcare' => StorageHelper::uploadcare(),
'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account),
'hasFile' => $contact->avatar['type'] === 'url',
],
Expand Down Expand Up @@ -109,7 +109,7 @@ public static function dataForTemplatePage(Contact $contact, User $user, Templat
'quick_fact_template_entries' => self::quickFacts($contact),
'modules' => self::modules($templatePage, $contact, $user),
'avatar' => [
'uploadcarePublicKey' => config('services.uploadcare.public_key'),
'uploadcare' => StorageHelper::uploadcare(),
'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account),
'hasFile' => $contact->avatar['type'] === 'url',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function data(Contact $contact): array

return [
'documents' => $documentsCollection,
'uploadcarePublicKey' => config('services.uploadcare.public_key'),
'uploadcare' => StorageHelper::uploadcare(),
'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account),
'url' => [
'store' => route('contact.document.store', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function data($files, Contact $contact): array
'name' => $contact->name,
],
'photos' => $photosCollection,
'uploadcarePublicKey' => config('services.uploadcare.public_key'),
'uploadcare' => StorageHelper::uploadcare(),
'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account),
'url' => [
'show' => route('contact.show', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function data(Contact $contact): array

return [
'photos' => $photosCollection,
'uploadcarePublicKey' => config('services.uploadcare.public_key'),
'uploadcare' => StorageHelper::uploadcare(),
'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account),
'url' => [
'index' => route('contact.photo.index', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function data(Journal $journal, Post $post, User $user): array
'tags_in_post' => $tagsAssociatedWithPostCollection,
'tags_in_vault' => $tagsInVaultCollection,
'journal_metrics' => self::journalMetrics($post),
'uploadcarePublicKey' => config('services.uploadcare.public_key'),
'uploadcare' => StorageHelper::uploadcare(),
'canUploadFile' => StorageHelper::canUploadFile($journal->vault->account),
'journal' => [
'name' => $journal->name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function data(SliceOfLife $slice): array
'slice' => self::dtoSlice($slice),
'posts' => $postsCollection,
'contacts' => $contactsCollection,
'uploadcarePublicKey' => config('services.uploadcare.public_key'),
'uploadcare' => StorageHelper::uploadcare(),
'canUploadFile' => StorageHelper::canUploadFile($slice->journal->vault->account),
'url' => [
'slices_index' => route('slices.index', [
Expand Down
15 changes: 15 additions & 0 deletions app/Helpers/StorageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Account;
use App\Models\File;
use Uploadcare\Security\Signature;

class StorageHelper
{
Expand All @@ -23,4 +24,18 @@ public static function canUploadFile(Account $account): bool

return $totalSizeInBytes < $accountLimit;
}

/**
* Get the Uploadcare data needed for the views.
*/
public static function uploadcare(): array
{
$signature = config('services.uploadcare.private_key') != '' ? new Signature(config('services.uploadcare.private_key')) : null;

return [
'publicKey' => config('services.uploadcare.public_key'),
'signature' => optional($signature)->getSignature(),
'expire' => optional(optional($signature)->getExpire())->getTimestamp(),
];
}
}
7 changes: 4 additions & 3 deletions resources/js/Pages/Vault/Contact/Photos/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@

<!-- upload -->
<uploadcare
v-if="data.uploadcarePublicKey && data.canUploadFile"
:public-key="data.uploadcarePublicKey"
v-if="data.uploadcare.publicKey && data.canUploadFile"
:public-key="data.uploadcare.publicKey"
:secure-signature="data.uploadcare.signature"
:secure-expire="data.uploadcare.expire"
:tabs="'file'"
:multiple="false"
:preview-step="false"
@success="onSuccess"
@error="onError">
Expand Down
7 changes: 4 additions & 3 deletions resources/js/Pages/Vault/Contact/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ const download = () => {
<!-- upload new avatar -->
<li v-if="!data.avatar.hasFile" class="mb-2">
<Uploadcare
v-if="data.avatar.uploadcarePublicKey && data.avatar.canUploadFile"
:public-key="data.avatar.uploadcarePublicKey"
v-if="data.avatar.uploadcare.publicKey && data.avatar.canUploadFile"
:public-key="data.avatar.uploadcare.publicKey"
:secure-signature="data.avatar.uploadcare.signature"
:secure-expire="data.avatar.uploadcare.expire"
:tabs="'file'"
:multiple="false"
:preview-step="false"
@success="onSuccess"
@error="onError">
Expand Down
11 changes: 6 additions & 5 deletions resources/js/Pages/Vault/Journal/Post/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ const destroy = () => {

<!-- upload component -->
<uploadcare
v-if="data.uploadcarePublicKey && data.canUploadFile"
:public-key="data.uploadcarePublicKey"
v-if="data.uploadcare.publicKey && data.canUploadFile"
:public-key="data.uploadcare.publicKey"
:secure-signature="data.uploadcare.signature"
:secure-expire="data.uploadcare.expire"
:tabs="'file'"
:multiple="false"
:preview-step="false"
@success="onSuccess"
@error="onError">
Expand All @@ -276,15 +277,15 @@ const destroy = () => {
<!-- case when there are photos -->
<div v-else class="mb-6 flex items-center">
<p
class="inline-block cursor-pointer rounded-lg border bg-slate-200 px-1 py-1 text-xs hover:bg-slate-300">
class="inline-block cursor-pointer rounded-lg border bg-slate-200 dark:bg-slate-700 px-1 py-1 text-xs hover:bg-slate-300 hover:dark:bg-slate-800">
{{ $t('+ add another photo') }}
</p>
</div>
</uploadcare>

<!-- uploadcare api key not set -->
<div
v-if="!data.uploadcarePublicKey"
v-if="!data.uploadcare.publicKey"
class="mb-6 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900">
<p class="p-5 text-center">
{{ $t('The keys to manage uploads have not been set in this Monica instance.') }}
Expand Down
9 changes: 5 additions & 4 deletions resources/js/Pages/Vault/Journal/Slices/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ const destroy = () => {
<div>
<!-- header image -->
<uploadcare
v-if="data.uploadcarePublicKey && data.canUploadFile && !localSlice.cover_image"
:public-key="data.uploadcarePublicKey"
v-if="data.uploadcare.publicKey && data.canUploadFile && !localSlice.cover_image"
:public-key="data.uploadcare.publicKey"
:secure-signature="data.uploadcare.signature"
:secure-expire="data.uploadcare.expire"
:tabs="'file'"
:multiple="false"
:preview-step="false"
@success="onSuccess"
@error="onError">
Expand All @@ -149,7 +150,7 @@ const destroy = () => {

<!-- uploadcare api key not set -->
<div
v-if="!data.uploadcarePublicKey"
v-if="!data.uploadcare.publicKey"
class="mb-6 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900">
<p class="p-5 text-center">
{{ $t('The keys to manage uploads have not been set in this Monica instance.') }}
Expand Down
9 changes: 5 additions & 4 deletions resources/js/Shared/Modules/Documents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
</span>
</div>
<uploadcare
v-if="data.uploadcarePublicKey && data.canUploadFile"
:public-key="data.uploadcarePublicKey"
v-if="data.uploadcare.publicKey && data.canUploadFile"
:public-key="data.uploadcare.publicKey"
:secure-signature="data.uploadcare.signature"
:secure-expire="data.uploadcare.expire"
:tabs="'file'"
:multiple="false"
:preview-step="false"
@success="onSuccess"
@error="onError">
Expand Down Expand Up @@ -87,7 +88,7 @@

<!-- uploadcare api key not set -->
<div
v-if="!data.uploadcarePublicKey"
v-if="!data.uploadcare.publicKey"
class="mb-6 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900">
<p class="p-5 text-center">
{{ $t('The keys to manage uploads have not been set in this Monica instance.') }}
Expand Down
9 changes: 5 additions & 4 deletions resources/js/Shared/Modules/Photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
</span>
</div>
<uploadcare
v-if="data.uploadcarePublicKey && data.canUploadFile"
:public-key="data.uploadcarePublicKey"
v-if="data.uploadcare.publicKey && data.canUploadFile"
:public-key="data.uploadcare.publicKey"
:secure-signature="data.uploadcare.signature"
:secure-expire="data.uploadcare.expire"
:tabs="'file'"
:multiple="false"
:preview-step="false"
@success="onSuccess"
@error="onError">
Expand Down Expand Up @@ -76,7 +77,7 @@

<!-- uploadcare api key not set -->
<div
v-if="!data.uploadcarePublicKey"
v-if="!data.uploadcare.publicKey"
class="mb-6 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900">
<p class="p-5 text-center">
{{ $t('The keys to manage uploads have not been set in this Monica instance.') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public function it_gets_the_data_needed_for_the_view(): void
);

$this->assertArrayHasKey('documents', $array);
$this->assertArrayHasKey('uploadcarePublicKey', $array);
$this->assertArrayHasKey('uploadcare', $array);
$this->assertArrayHasKey('canUploadFile', $array);
$this->assertArrayHasKey('url', $array);

$this->assertEquals(
'123',
$array['uploadcarePublicKey']
$array['uploadcare']['publicKey']
);
$this->assertFalse($array['canUploadFile']);
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function it_gets_the_data_needed_for_the_view(): void
);
$this->assertEquals(
'123',
$array['uploadcarePublicKey']
$array['uploadcare']['publicKey']
);
$this->assertTrue($array['canUploadFile']);
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public function it_gets_the_data_needed_for_the_view(): void
);

$this->assertArrayHasKey('photos', $array);
$this->assertArrayHasKey('uploadcarePublicKey', $array);
$this->assertArrayHasKey('uploadcare', $array);
$this->assertArrayHasKey('canUploadFile', $array);
$this->assertArrayHasKey('url', $array);

$this->assertEquals(
'123',
$array['uploadcarePublicKey']
$array['uploadcare']['publicKey']
);
$this->assertFalse($array['canUploadFile']);
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function it_gets_the_data_needed_for_the_view(): void
);
$this->assertEquals(
'123',
$array['uploadcarePublicKey']
$array['uploadcare']['publicKey']
);
$this->assertTrue(
$array['canUploadFile']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function it_gets_the_data_needed_for_the_view(): void
);
$this->assertEquals(
'123',
$array['uploadcarePublicKey']
$array['uploadcare']['publicKey']
);
$this->assertTrue(
$array['canUploadFile']
Expand Down

0 comments on commit e9c4f9d

Please sign in to comment.