Commit Graph

56 Commits

Author SHA1 Message Date
Damien Elmes
4a5ef69068 add remaining types and disable missing types on (almost) all aqt 2021-02-03 00:00:29 +10:00
Damien Elmes
a56b09b987 add a bunch of return types 2021-02-01 23:53:23 +10:00
Damien Elmes
f15715fb07 add types to various other files
Mainly automated with MonkeyType
2021-02-01 22:08:56 +10:00
Damien Elmes
6c483bb577 add public wrappers for remaining backend functions 2021-01-31 18:56:16 +10:00
Damien Elmes
9d853bbb03 start work on more clearly defining backend/protobuf boundaries
- anki._backend stores the protobuf files and rsbackend.py code
- pylib modules import protobuf messages directly from the
_pb2 files, and explicitly export any will be returned or consumed
by public pylib functions, so that calling code can import from pylib
- the "rsbackend" no longer imports and re-exports protobuf messages
- pylib can just consume them directly.
- move errors to errors.py

Still todo:

- rsbridge
- finishing the work on rsbackend, and check what we need to add
back to the original file location to avoid breaking add-ons
2021-01-31 18:55:45 +10:00
Damien Elmes
4ac9ad1407 show actual error when graphData fails
The original reason for the catch-all message was users with bad
data such as decimal intervals, but those get automatically coerced
these days. The common case should now be invalid search strings, which
we can show verbatim.
2021-01-29 14:39:05 +10:00
Damien Elmes
37ca8afaf6 minor wording tweak: GraphsPreferences -> GraphPreferences 2021-01-23 20:47:45 +10:00
Henrik Giesel
bf130d1da0 Change the function name in genbackend.py 2021-01-22 20:05:28 +01:00
Henrik Giesel
de71123ab4 Rename GraphsPreferencesOut to simply GraphsPreferences 2021-01-22 19:39:03 +01:00
Henrik Giesel
d1ada88657 Successfully send post request to rust 2021-01-22 14:37:24 +01:00
Henrik Giesel
054c30a695 Add non-functioning logic for settings graphs preferences 2021-01-22 13:14:35 +01:00
Henrik Giesel
665a13e378 Add GraphsPreferences endpoint to backend 2021-01-22 13:13:48 +01:00
Henrik Giesel
ffc40d8959 Replace browsersel with css-browser-selector in aqt files and add redirect 2020-12-31 16:47:20 +01:00
Henrik Giesel
ed8b12e1d6 Add redirect for jquery-ui 2020-12-30 12:08:12 +01:00
Damien Elmes
9e1eaacc06 Revert "Merge pull request #873 from hgiesel/otherjsdeps"
This reverts commit 62600051ae, reversing
changes made to 88553acb0d.

- Standard graphs render incorrectly on latest version - the wrong number
of days are shown, and the grid lines look wrong. Any version after 0.8.3
seems to suffer from this problem.
- Pie graphs and stack graphs don't render - they are provided in separate
files, and plot.js in previous Anki versions has them included in the one
file. To maintain compatibility with add-ons, we'd need to create a single
file as before, instead of importing multiple files.

If the above issues are fixed I'd be happy to merge this in again, but
as the old graphs are on the way out, it's probably not worth the effort.
2020-12-30 14:13:52 +10:00
Henrik Giesel
a6319326a9 Redirect references to old plotting library version 2020-12-29 12:15:46 +01:00
Damien Elmes
666d847a0a
Merge pull request #856 from hgiesel/jquery
Update jQuery from 1.12.4 to 3.5.1, include in Bazel build process
2020-12-29 10:00:33 +10:00
Damien Elmes
d8778da3e8 fix legacy js remapping
Thanks to Henrik for catching it.
2020-12-29 09:57:34 +10:00
Henrik Giesel
202fd6ffa5 Add mapping in redirectWebExport for new jquery file 2020-12-28 14:52:44 +01:00
Damien Elmes
a61f3bbc48 fix some warnings on startup 2020-12-16 15:38:24 +10:00
ianki
c2901e4859 Add hooks for filtering media. 2020-11-09 02:12:23 -08:00
Damien Elmes
ecfeb71195 fix tests on Linux 2020-11-04 21:39:41 +10:00
Damien Elmes
aea0a6fcc6 initial Bazel conversion
Running and testing should be working on the three platforms, but
there's still a fair bit that needs to be done:

- Wheel building + testing in a venv still needs to be implemented.
- Python requirements still need to be compiled with piptool and pinned;
need to compile on all platforms then merge
- Cargo deps in cargo/ and rslib/ need to be cleaned up, and ideally
unified into one place
- Currently using rustls to work around openssl compilation issues
on Linux, but this will break corporate proxies with custom SSL
authorities; need to conditionally use openssl or use
https://github.com/seanmonstar/reqwest/pull/1058
- Makefiles and docs still need cleaning up
- It may make sense to reparent ts/* to the top level, as we don't
nest the other modules under a specific language.
- rspy and pylib must always be updated in lock-step, so merging
rspy into pylib as a private module would simplify things.
- Merging desktop-ftl and mobile-ftl into the core ftl would make
managing and updating translations easier.
- Obsolete scripts need removing.
- And probably more.
2020-11-01 14:26:58 +10:00
Henrik Giesel
70aed820da Set MIME type for javascript files 2020-10-26 23:32:38 +01:00
Damien Elmes
ac265fe75a formatting fixes for latest black 2020-09-01 10:24:38 +10:00
Damien Elmes
e5685254c6 reimplement congrats screen in Rust+Typescript 2020-09-01 10:24:38 +10:00
Damien Elmes
a517accee3 update to latest black 2020-08-31 13:29:28 +10:00
Damien Elmes
18c59c60a4 unnecessary f-string 2020-08-04 17:52:49 +10:00
Damien Elmes
440aa129d9 disable media get / posts when collection closed
https://forums.ankiweb.net/t/countdown-to-events-exams-addon-official-thread/1093/4?u=dae
2020-08-04 10:03:17 +10:00
Damien Elmes
c1ecb7b827 fix untyped def issues in aqt/mediasrv.py 2020-08-02 10:22:21 +10:00
Damien Elmes
f45627dbd3 don't throw error on empty path
https://forums.ankiweb.net/t/anki-2-1-28-error-message-when-reviewing-cards/1439
2020-07-27 11:28:32 +10:00
Damien Elmes
2cba721702 formatting and debug statement tweak 2020-07-24 11:57:37 +10:00
Damien Elmes
80a2bfa642 ask user to check db when graphs fail to load 2020-07-24 09:56:28 +10:00
Damien Elmes
320b56ae43 can't rely on stdout to handle unicode 2020-07-15 09:36:29 +10:00
Damien Elmes
bc5b6dfb63 mediasrv symlink fix
https://forums.ankiweb.net/t/anki-2-1-28-beta/629/39
2020-07-11 10:53:41 +10:00
Damien Elmes
93425be839 formatting 2020-07-07 13:28:30 +10:00
Damien Elmes
85cbd263da tidy up logging 2020-07-07 10:50:12 +10:00
Damien Elmes
4ab9d04c95 if webexports does not match, return 403 2020-07-07 10:50:03 +10:00
evandrocoan
121725390d Fix _addons/ URL prefix not being removed on Windows systems
Anki 2.1.28 Beta
https://forums.ankiweb.net/t/anki-2-1-28-beta/629/26

> Did the requirements on how to expose resources on the internal server change? Because scripts, css files and the like, registered with setWebExports, do not work anymore with beta2.
> A look at the console shows the following for all resources:
> Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)

**\Anki2\addons21\someaddon\__init__.py**
```py
from aqt import mw
import aqt

# assuming add-on folder is named "test"
# and assuming a 'test.js' is in the same folder
addon_id = "someaddon"
port = mw.mediaServer.getPort()
mw.addonManager.setWebExports(addon_id, ".*\\.js$")

print("Hello")

aqt.editor._html += f"""
<script>
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://127.0.0.1:{port}/_addons/{addon_id}/test.js';
    document.body.appendChild(script);
</script>"""
```
2020-07-06 13:51:37 -03:00
Damien Elmes
4033f00988 don't stuff mw into function objects
Using the global is preferable to fighting against mypy to insert mw
into a function object.
2020-07-03 10:55:29 +10:00
Damien Elmes
14602be0ca port previous css workaround to flask 2020-07-03 10:40:23 +10:00
evandrocoan
476b881987 Replaced flask.Response by flask.make_response to simplify the
implementation and because make_response is preferred over Response
as it respects the server defined Response type.
2020-07-02 20:39:03 -03:00
evandrocoan
a99e455414 Removed duplicated mediasrv.py security check and fixed invalid
command/path error message.
2020-07-02 20:39:03 -03:00
evandrocoan
1218d109e8 Fix jest unit tests after merge
# Conflicts:
#	qt/aqt/mediasrv.py
#	qt/ts/src/ankimedia.ts
#	qt/ts/src/reviewer-exceptions.test.ts
#	qt/ts/src/reviewer.test.ts
#	ts/package.json
2020-07-02 14:30:43 -03:00
evandrocoan
0142ac3ca2 Replaced send_from_directory by send_file to simplify the code 2020-07-02 13:52:07 -03:00
evandrocoan
1e6fa5f8eb Ensure protection against directory transversal
https://security.openstack.org/guidelines/dg_using-file-paths.html
2020-07-02 13:52:03 -03:00
evandrocoan
be10da58d9 Fixed aqt/mediasrv.py:14: error: unused 'type: ignore' comment
from waitress.server import create_server  # type: ignore
https://github.com/evandroforks/anki/runs/743801391#step:25:1129
2020-07-02 13:51:59 -03:00
evandrocoan
020415efb9 Replaced the mediasrv.py SimpleHttp server by flask and waitress,
fixing HTML5 media support.
https://stackoverflow.com/questions/37044064/html-audio-cant-set-currenttime
https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
https://stackoverflow.com/questions/5052635/what-is-relation-between-content-length-and-byte-ranges-in-http-1-1
https://stackoverflow.com/questions/16725907/google-app-engine-serving-mp3-for-audio-element-needs-content-range-header

I was trying to use HTML5 audio tag to display audios like:
```html
<audio id="elem_audio" src="myfile.mp3" controls></audio>
```
![image](https://user-images.githubusercontent.com/5332158/79063321-565b5500-7c77-11ea-9f8d-6e1df6f07892.png)

But the progress bar seek was not working. After researching, I found the problem was the HTML server not properly responding to the HTML5 header requests. The HTML server should respond to quite complicated things as 206 partial, properly handle keep-alive, provide media ranges and other HTTP headers: https://stackoverflow.com/questions/37044064/html-audio-cant-set-currenttime

To implement all these on the Simple HTTP server would be quite complicated. Then, instead, I imported the `flask` web server, which is quite simple and straight forward to use. Now, the back-end is using a secure complaint HTTP back-end:
1. https://palletsprojects.com/p/flask/
    > Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. It began as a simple wrapper around Werkzeug and Jinja and has become one of the most popular Python web application frameworks.
    >
    > Flask offers suggestions, but doesn't enforce any dependencies or project layout. It is up to the developer to choose the tools and libraries they want to use. There are many extensions provided by the community that make adding new functionality easy.

1. https://docs.pylonsproject.org/projects/waitress/en/latest/
    > Waitress is meant to be a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones which live in the Python standard library. It runs on CPython on Unix and Windows under Python 2.7+ and Python 3.5+. It is also known to run on PyPy 1.6.0 on UNIX. It supports HTTP/1.0 and HTTP/1.1.

Right now, anki does not support fields passing file names directly to HTML audio tags, but this can be easily done with (https://github.com/ankitects/anki/pull 540 - Added arguments to the sound tag) plus the commit 826a97df61, the HTML5 audio tag can be used like this:
```html
// Audio = [sound:myfile.mp3|onlyfilename]
<audio id="elem_audio" src="{{Audio}}" controls controlsList="nodownload"></audio>
```
![image](https://user-images.githubusercontent.com/5332158/79063736-c539ad80-7c79-11ea-8420-40b72185f4e7.png)

# Conflicts:
#	qt/aqt/mediasrv.py
2020-07-02 13:51:49 -03:00
Damien Elmes
d4cd4535e6 lint fixes 2020-06-29 15:53:56 +10:00
Damien Elmes
41d77b0255 get i18n working in typescript 2020-06-29 15:48:01 +10:00