Commit graph

70 commits

Author SHA1 Message Date
Damien Elmes
372d5ed6e8 update copyright and clarify licenses 2019-02-05 14:01:33 +10:00
Damien Elmes
7b96e90db7 cap filename length when attaching media to cards
https://anki.tenderapp.com/discussions/ankidesktop/30953-can-not-paste-or-upload-images-into-deck
2018-11-27 14:45:38 +10:00
Damien Elmes
01832e1312 fix media check with [$]{{c1::a}}{{c2::b}}[/$]
https://anki.tenderapp.com/discussions/ankidesktop/28625-cloze-deletion-in-latex-check-medias-regression-in-21

appears to have broken in e3885fd924
2018-06-28 13:11:04 +10:00
Damien Elmes
88fe45b1bb normalize to NFC on all platforms
APFS is normalization-preserving, which results in spurious changes
being detected if we assume we'll receive NFD from file listings

this needs to be ported to 2.0.x as well
2018-02-28 16:22:06 +10:00
Damien Elmes
7ac601f0af fix 'unclosed file' warnings with python -Wall 2017-12-11 16:38:15 +10:00
Damien Elmes
5ee1ee0450 restore media dir mod check
https://anki.tenderapp.com/discussions/beta-testing/853-anki-210-beta-21/page/1#comment_44071381
2017-11-20 14:22:53 +10:00
Damien Elmes
8e7ef1d1be detect image extension, catch errors, add timeout 2017-11-17 17:30:01 +10:00
Damien Elmes
e3885fd924 fix detection of media refs in cloze
https://anki.tenderapp.com/discussions/beta-testing/796-another-check-media-issue
2017-10-18 21:56:57 +10:00
Damien Elmes
67728e73d7 fix broken cloze deletion 2017-09-10 19:51:25 +10:00
Damien Elmes
5fd9228273 handle invalid filename encodings
on Linux users can end up creating filenames that can't be encoded to utf8,
which breaks Anki when it tries to store the filename in sqlite
2017-08-31 18:55:25 +10:00
Damien Elmes
c18bd47a6e scan media each time
Experiment with ignoring dirMod and scanning the folder for changes on
each sync. Use scandir() for better performance. Please let me know if
this causes a noticeable slowdown for you.
2017-08-29 10:52:13 +10:00
Damien Elmes
3faa82571c warn about subfolders 2017-08-28 22:01:13 +10:00
Damien Elmes
3ad9261c8c catch corrupt media db, fix it in 'check media' 2017-08-17 13:33:54 +10:00
Damien Elmes
aa89d06304 Revert "don't rely on cwd in media.py"
This reverts commit 975ca90225.

reverting for now as it breaks showing of images during review
2017-04-11 12:50:33 +10:00
Joel Kitching
975ca90225 don't rely on cwd in media.py
media.py sets CWD to the media directory of the collection
(collection.media), and relies on that directory being
maintained as CWD throughout execution.  The original CWD
is restored in the close() function.

Remove reliance on CWD being set and maintained throughout
execution of media.py.  Improves portability and usability
in different codebases.
2017-03-07 15:55:40 +08:00
Illia Volochii
13b7e01044 Stop inheriting from object
It is not needed in Python 3.
2017-02-07 00:21:33 +02:00
dequis
9c902aec18 Turn "vacuum analyze" into two commands (fix for sqlite 3.15)
Before sqlite 3.15, the parameter to vacuum was ignored. Since sqlite
3.15, it became a database name parameter. The "vacuum analyze" syntax
was never supported by sqlite, seems to be just a psql thing.

The error for this is "OperationalError: unknown database analyze", and
happens when doing a media sync.
2017-01-15 13:25:21 -03:00
Damien Elmes
e6adc3c195 fixes for sqlite on python 3.6
we need to switch to autocommit mode before executing vacuums &
certain pragmas

also removed the pysqlite version workaround; we just use the
python-provided versions in all cases now as it is new enough
2017-01-13 17:00:03 +10:00
Damien Elmes
e8423f0874 fix a bug that caused media data not to be uploaded 2017-01-02 20:53:15 +10:00
Damien Elmes
94463991bc basic sync support
currently no progress shown on large uploads/downloads
2016-07-04 15:45:53 +10:00
Damien Elmes
15b349e3a8 start port to python 3
unit tests pass and main screens of GUI load
2016-05-12 14:45:35 +10:00
Damien Elmes
25c041bc0f unquote does need utf8, but we need to convert back to unicode after 2014-08-05 12:59:31 +09:00
Damien Elmes
08510a4a53 Revert "we shouldn't encode to utf8 when unquoting"
This reverts commit 2dd28d86a2.
2014-08-05 12:58:14 +09:00
Damien Elmes
2dd28d86a2 we shouldn't encode to utf8 when unquoting 2014-08-04 12:54:54 +09:00
Damien Elmes
d53346d783 limit url unquoting to image tags
this prevents random text like %20 in a field from being converted
when note is saved
2014-08-01 09:42:28 +09:00
Damien Elmes
dd2b6cb07d ignore >100MB files 2014-07-30 04:32:18 +09:00
Damien Elmes
cf801e4fb4 display more feedback when syncing media
deletes in particular take some time for the server to process, but
don't require much bandwidth, leading to the progress appearing to
have pause when content is actually being processed

this also gives the user an idea of how long the process will take to
complete
2014-07-28 17:00:26 +09:00
Damien Elmes
f54f5870fa deauthing should reset lastUsn to 0
thanks to houssam for the heads up!
2014-07-20 03:37:31 +09:00
Damien Elmes
3224a155a7 normalize filenames as we sync
user still needs to run "check media" if their fields are encoded
incorrectly, but by fixing on the fly we'll ensure mediaSanity doesn't
fail
2014-07-15 11:49:03 +09:00
Damien Elmes
d3807e3180 don't redetect delete which leads to sync error 2014-07-08 13:45:29 +09:00
Damien Elmes
999c53b5ec fix another downgrade+upgrade bug 2014-07-05 11:37:28 +09:00
Damien Elmes
1cb2aa077a must make sure to detach old media db before renaming 2014-07-05 07:21:32 +09:00
Damien Elmes
014787c4cb log mediaChangesZip() 2014-07-04 18:14:45 +09:00
Damien Elmes
eba3aa583c if media.db import fails, start anew 2014-06-28 05:06:43 +09:00
dae
2aa7714f87 new media syncing protocol
- media syncing no longer locks the account, so it can be done
  in the background in the future, and multiple clients can safely
  sync media at the same time
- all operations are now idempotent, so they can be repeatedly safely
  in the event of a connection error
- whether it's a normal incremental sync, an initial sync,
  or the media database has been deleted, no files will be uploaded
  or downloaded if they already exist on the other side
- file removals are now chunked like additions & updates, preventing
  timeouts due to large requests
- if the server can't process a chunk in time, it will return a count
  of what it did process, so the client can retry the rest

Notes for AnkiDroid:

- when porting this, recommend you pick a different name for the
.media.db2 file, so users don't accidentally copy the AD version to
the desktop or vice versa
- please make sure filenames are added to the zip in NFC form
2014-06-26 09:00:38 +09:00
Damien Elmes
de8adfecff disallow \r and \n in media filenames 2014-03-06 09:00:47 +09:00
Damien Elmes
f0525a76fb if we renamed any files to nfc, need to rerun check 2013-12-13 20:24:39 +09:00
Damien Elmes
54e2d42fa6 off by one in zip count comparison 2013-12-09 17:37:43 +09:00
Damien Elmes
ba589ac8cc need to compare mediaList with nfd on macs
otherwise the server says we have file x and local code
doesn't notice it already exists
2013-12-04 11:43:57 +09:00
Damien Elmes
1c35a590e3 fix regression in unused media check 2013-11-29 02:07:31 +09:00
Damien Elmes
0372f30220 adjust media regexp to not trigger on mce_src
otherwise pasting the following will cause an error:

<img src="..." mce_src="/foo.png">
2013-11-27 19:24:41 +09:00
Damien Elmes
99d82c1f2d fix hasIllegal check, and associated unit test 2013-11-26 03:19:11 +09:00
Damien Elmes
f6b9dadf13 catch invalid file encodings in media check & sync 2013-11-13 17:19:25 +09:00
Damien Elmes
5f0ef85044 fix reversed check in media 2013-10-30 21:10:25 +09:00
Damien Elmes
82a54c780f catch invalid temp folder and other tweaks
- tweak sync code so that a failure in loading the collection
  won't leave the app with an unopen collection
- don't show corrupt collection message when the error is not
  a db error
- catch the temp folder issue when loading the collection. i suspect
  this was the issue that was causing some people to end up with
  an open anki instance with no collection loaded
2013-10-22 15:30:53 +09:00
Damien Elmes
da1672d42f don't rename/unlink files for non-local check 2013-10-17 17:59:26 +09:00
Damien Elmes
6be7503543 normalize to nfc when sending media in sync 2013-10-16 08:37:34 +09:00
Damien Elmes
b42c0c725b Revert "tolerate a str arg to writeData()"
This reverts commit 2d4e88afbd.

On second thought, this change is likely to mask the error in most cases, and
we want add-on authors to update their add-ons anyway as they would not be
handling non-latin text in 2.0.12.
2013-10-10 11:08:39 +09:00
Damien Elmes
2d4e88afbd tolerate a str arg to writeData() 2013-10-09 13:13:48 +09:00
Damien Elmes
6c304ebe2f to normalize unicode we need to have unicode 2013-10-06 04:53:11 +09:00