Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit f043f9a

Browse files
committed
uploads have to be zipped #5
This is a first rough fix. Uploads are exactly like downolads, so the file needs to be wrapped into a zip and metadata needs to be added. This seems to make the upload work as planned. But it needs some more testing and refactoring.
1 parent c302a98 commit f043f9a

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"require": {
1313
"ramsey/uuid": "^3.7",
1414
"guzzlehttp/guzzle": "^6.3",
15-
"psr/log": "^1.0"
15+
"psr/log": "^1.0",
16+
"splitbrain/php-archive": "^1.0"
1617
},
1718
"require-dev": {
1819
"splitbrain/php-cli": "^1.1"

composer.lock

Lines changed: 52 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

remarkable.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ protected function cmdUpload($file, $parent, $uuid)
148148
$parent = $fs->mkdirP($parent);
149149
}
150150

151-
$stream = \GuzzleHttp\Psr7\stream_for($file);
152151
$name = basename($file);
153-
$this->api->uploadDocument($stream, $name, $parent);
152+
$this->api->uploadDocument(file_get_contents($file), $name, $parent);
154153
}
155154

156155
/**
@@ -166,7 +165,7 @@ protected function cmdDownload($file, $to, $uuid)
166165
if (!$uuid) {
167166
$fs = new RemarkableFS($this->api);
168167
$item = $fs->findFirst($file, RemarkableAPI::TYPE_DOCUMENT);
169-
if($item === null) throw new \Exception('Document not found');
168+
if ($item === null) throw new \Exception('Document not found');
170169
$file = $item['ID'];
171170
}
172171

src/RemarkableAPI.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Psr\Log\LoggerInterface;
88
use Psr\Log\NullLogger;
99
use Ramsey\Uuid\Uuid;
10+
use splitbrain\PHPArchive\Zip;
1011

1112
/**
1213
* Class RemarkableAPI
@@ -227,6 +228,23 @@ public function uploadDocument($body, $name, $parentID = '')
227228
];
228229
$item = $this->createUploadRequest($stub);
229230

231+
# FIXME once this works it needs refactoring
232+
$zip = new Zip();
233+
$zip->create();
234+
$zip->addData($stub['ID'] . '.pdf', (string)$body);
235+
$zip->addData($stub['ID'] . '.pagedata', '');
236+
$zip->addData($stub['ID'] . '.content', json_encode([
237+
'extraMeatadata' => [],
238+
'fileType' => 'pdf',
239+
'lastOpenedPage' => 0,
240+
'lineHeight' => -1,
241+
'margins' => 100,
242+
# 'pageCount' => 1, #FIXME how to find out
243+
'textScale' => 1,
244+
'transform' => [] #FIXME wtf is this?
245+
], JSON_PRETTY_PRINT));
246+
$body = $zip->getArchive();
247+
230248
if (!isset($item['BlobURLPut'])) {
231249
print_r($item);
232250
throw new \Exception('No put url');

src/RemarkableFS.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getTree()
8080
public function mkdirP($folder)
8181
{
8282
$folder = trim($folder, '/');
83-
if($folder === '') return '';
83+
if ($folder === '') return '';
8484
$parts = explode('/', $folder);
8585

8686
$current = '';

0 commit comments

Comments
 (0)