Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
protokollsystem
proto3
Commits
590d8030
Unverified
Commit
590d8030
authored
Nov 19, 2020
by
Robin Sonnabend
Browse files
Use etherpad API for pad content push/pull
parent
b4860e32
Changes
2
Hide whitespace changes
Inline
Side-by-side
configproxy.py
View file @
590d8030
...
...
@@ -376,7 +376,7 @@ def check_printing(PRINTING_SERVER, PRINTING_USER, PRINTING_PRINTERS):
printer
,
value
,
name
,
available_options
[
name
]))
def
check_etherpad
(
ETHERPAD_URL
,
EMPTY_ETHERPAD
):
def
check_etherpad
(
ETHERPAD_URL
,
ETHERPAD_APIKEY
,
EMPTY_ETHERPAD
):
import
requests
try
:
answer
=
requests
.
get
(
ETHERPAD_URL
)
...
...
@@ -822,6 +822,11 @@ CONFIG_SECTIONS = [
description
=
(
"URL of the etherpad installation. "
"Do not include the '/p'!"
)),
ConfigEntry
(
name
=
"ETHERPAD_APIKEY"
,
default
=
"abc123"
,
required
=
True
,
internal
=
True
,
no_sane_default
=
True
,
description
=
"Key to access the etherpad API"
),
ConfigEntry
(
name
=
"EMPTY_ETHERPAD"
,
default
=
"
\n
"
.
join
([
...
...
utils.py
View file @
590d8030
...
...
@@ -16,6 +16,8 @@ from uuid import uuid4
import
subprocess
import
contextlib
from
etherpad_lite
import
EtherpadLiteClient
as
EtherpadClient
from
shared
import
config
...
...
@@ -136,31 +138,29 @@ def get_etherpad_url(pad):
return
"{}/p/{}"
.
format
(
config
.
ETHERPAD_URL
,
normalize_pad
(
pad
))
def
get_etherpad_export_url
(
pad
):
return
"{}/p/{}/export/txt"
.
format
(
config
.
ETHERPAD_URL
,
normalize_pad
(
pad
))
def
get_etherpad_api_url
():
return
"{}/api"
.
format
(
config
.
ETHERPAD_URL
)
def
get_etherpad_
import_url
(
pad
):
return
"{}/p/{}/import"
.
format
(
config
.
ETHERPAD_URL
,
normalize_pad
(
pad
))
def
get_etherpad_
api_client
(
):
return
EtherpadClient
(
base_url
=
get_etherpad_api_url
(),
api_version
=
"1.2.14"
,
base_params
=
dict
(
apikey
=
config
.
ETHERPAD_APIKEY
))
def
get_etherpad_text
(
pad
):
req
=
requests
.
get
(
get_etherpad_export_url
(
pad
)
)
return
req
.
text
client
=
get_etherpad_api_client
(
)
return
client
.
getText
(
padID
=
pad
)[
"text"
]
def
set_etherpad_text
(
pad
,
text
,
only_if_default
=
True
):
client
=
get_etherpad_api_client
()
if
only_if_default
:
current_text
=
get_etherpad_text
(
pad
).
strip
()
if
(
current_text
!=
config
.
EMPTY_ETHERPAD
.
strip
()
and
"<pre>Cannot GET /p"
not
in
current_text
and
len
(
current_text
)
>
0
):
return
False
file_like
=
BytesIO
(
text
.
encode
(
"utf-8"
))
files
=
{
"file"
:
(
"content.txt"
,
file_like
,
"text/plain"
)}
url
=
get_etherpad_import_url
(
pad
)
req
=
requests
.
post
(
url
,
files
=
files
)
return
req
.
status_code
==
200
client
=
get_etherpad_api_client
()
client
.
setText
(
padID
=
pad
,
text
=
text
)
return
True
def
split_terms
(
text
,
quote_chars
=
"
\"
'"
,
separators
=
"
\t\n
"
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment