-
Notifications
You must be signed in to change notification settings - Fork 38
feat(photos): Add Google Photos import via Picker API #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8dfe44b
693ecff
fce8b2f
19a71c6
bb64738
5c07f42
b645069
bb3a630
b5b2ba6
f8dc716
a47d6ef
3917b1f
d1373d5
2997756
0eb485a
b30ecd3
ed03d8b
20f7ce3
c925e35
18cc183
fb98be3
c1b41e7
18d5942
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Nextcloud - integration_google | ||
| * | ||
| * This file is licensed under the Affero General Public License version 3 or | ||
| * later. See the COPYING file. | ||
| * | ||
| * @author Ahsan Ahmed | ||
| * @copyright Nextcloud GmbH and Nextcloud contributors 2026 | ||
| */ | ||
|
|
||
| namespace OCA\Google\BackgroundJob; | ||
|
|
||
| use OCA\Google\Service\GooglePhotosAPIService; | ||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\BackgroundJob\QueuedJob; | ||
|
|
||
| /** | ||
| * A QueuedJob to partially import google photos and launch following job | ||
| */ | ||
| class ImportPhotosJob extends QueuedJob { | ||
|
|
||
| public function __construct( | ||
| ITimeFactory $timeFactory, | ||
| private GooglePhotosAPIService $service, | ||
| ) { | ||
| parent::__construct($timeFactory); | ||
| } | ||
|
|
||
| /** | ||
| * @param array{user_id:string} $argument | ||
| */ | ||
| public function run($argument) { | ||
| $userId = $argument['user_id']; | ||
| $this->service->importPhotosJob($userId); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,9 +20,14 @@ | |||||||||||||||||||||
| use OCA\Google\AppInfo\Application; | ||||||||||||||||||||||
| use OCP\AppFramework\Services\IAppConfig; | ||||||||||||||||||||||
| use OCP\Config\IUserConfig; | ||||||||||||||||||||||
| use OCP\Files\Folder; | ||||||||||||||||||||||
| use OCP\Files\InvalidPathException; | ||||||||||||||||||||||
| use OCP\Files\NotPermittedException; | ||||||||||||||||||||||
| use OCP\Http\Client\IClientService; | ||||||||||||||||||||||
| use OCP\Http\Client\IResponse; | ||||||||||||||||||||||
| use OCP\IL10N; | ||||||||||||||||||||||
| use OCP\Lock\ILockingProvider; | ||||||||||||||||||||||
| use OCP\Lock\LockedException; | ||||||||||||||||||||||
| use OCP\Notification\IManager as INotificationManager; | ||||||||||||||||||||||
| use Psr\Log\LoggerInterface; | ||||||||||||||||||||||
| use Throwable; | ||||||||||||||||||||||
|
|
@@ -353,6 +358,71 @@ public function simpleDownload(string $userId, string $url, $resource, array $pa | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Download content from a URL and save it as a new file in a folder. | ||||||||||||||||||||||
| * Handles resource management, timestamp setting, and cleanup on failure. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * @param string $userId | ||||||||||||||||||||||
| * @param Folder $saveFolder Target Nextcloud folder | ||||||||||||||||||||||
| * @param string $fileName Name of the file to create | ||||||||||||||||||||||
| * @param string $fileUrl URL to download from | ||||||||||||||||||||||
| * @param int|null $mtime Unix timestamp for the file modification time; uses current time if null | ||||||||||||||||||||||
| * @param array $params Additional HTTP query parameters | ||||||||||||||||||||||
| * @return int|null downloaded file size in bytes, or null on failure | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| public function downloadAndSaveFile( | ||||||||||||||||||||||
| string $userId, | ||||||||||||||||||||||
| Folder $saveFolder, | ||||||||||||||||||||||
| string $fileName, | ||||||||||||||||||||||
| string $fileUrl, | ||||||||||||||||||||||
| ?int $mtime = null, | ||||||||||||||||||||||
| array $params = [], | ||||||||||||||||||||||
| ): ?int { | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| $savedFile = $saveFolder->newFile($fileName); | ||||||||||||||||||||||
| } catch (NotPermittedException|InvalidPathException $e) { | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| $resource = $savedFile->fopen('w'); | ||||||||||||||||||||||
| } catch (LockedException $e) { | ||||||||||||||||||||||
| if ($savedFile->isDeletable()) { | ||||||||||||||||||||||
| $savedFile->delete(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
|
Comment on lines
+387
to
+393
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if ($resource === false) { | ||||||||||||||||||||||
AhsanIsEpic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| if ($savedFile->isDeletable()) { | ||||||||||||||||||||||
| $savedFile->delete(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
|
Comment on lines
+395
to
+399
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $res = $this->simpleDownload($userId, $fileUrl, $resource, $params); | ||||||||||||||||||||||
| if (!isset($res['error'])) { | ||||||||||||||||||||||
| if (is_resource($resource)) { | ||||||||||||||||||||||
| fclose($resource); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if ($mtime !== null) { | ||||||||||||||||||||||
| $savedFile->touch($mtime); | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| $savedFile->touch(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| $stat = $savedFile->stat(); | ||||||||||||||||||||||
| return (int)($stat['size'] ?? 0); | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| if (is_resource($resource)) { | ||||||||||||||||||||||
| fclose($resource); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if ($savedFile->isDeletable()) { | ||||||||||||||||||||||
| $savedFile->unlock(ILockingProvider::LOCK_EXCLUSIVE); | ||||||||||||||||||||||
| $savedFile->delete(); | ||||||||||||||||||||||
|
Comment on lines
+419
to
+420
|
||||||||||||||||||||||
| $savedFile->unlock(ILockingProvider::LOCK_EXCLUSIVE); | |
| $savedFile->delete(); | |
| try { | |
| $savedFile->unlock(ILockingProvider::LOCK_EXCLUSIVE); | |
| } catch (\Throwable $e) { | |
| } | |
| try { | |
| $savedFile->delete(); | |
| } catch (\Throwable $e) { | |
| } |
Uh oh!
There was an error while loading. Please reload this page.