2021-10-14 17:56:01 +04:00
|
|
|
import lxml.html
|
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
from . import atserver
|
|
|
|
from . import atconnect
|
|
|
|
|
|
|
|
FTYPE_FILE = 0
|
|
|
|
FTYPE_DIR = 1
|
|
|
|
|
|
|
|
class AternosFile:
|
|
|
|
|
2021-10-14 18:41:57 +04:00
|
|
|
def __init__(
|
|
|
|
atserv:atserver.AternosServer,
|
|
|
|
path:str, name:str, ftype:int=FTYPE_FILE,
|
|
|
|
size:Union[]=0) -> None:
|
2021-10-14 17:56:01 +04:00
|
|
|
|
|
|
|
self.atserv = atserv
|
|
|
|
self._name = name
|
|
|
|
self._ftype = ftype
|
2021-10-14 18:41:57 +04:00
|
|
|
self._size = float(size)
|
2021-10-14 17:56:01 +04:00
|
|
|
|
2021-10-14 18:41:57 +04:00
|
|
|
def delete(self) -> None:
|
2021-10-14 17:56:01 +04:00
|
|
|
|
|
|
|
self.atserv.atserver_request(
|
|
|
|
'https://aternos.org/panel/ajax/delete.php',
|
|
|
|
atconnect.REQPOST, data={'file': self._name},
|
|
|
|
sendtoken=True
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
2021-10-14 18:41:57 +04:00
|
|
|
def text(self) -> str:
|
2021-10-14 17:56:01 +04:00
|
|
|
editor = self.atserv.atserver_request(
|
|
|
|
f'https://aternos.org/files/{self._name}',
|
|
|
|
atconnect.REQGET
|
|
|
|
)
|
|
|
|
edittree = lxml.html.fromstring(editor.content)
|
|
|
|
|
|
|
|
editfield = edittree.xpath('//div[@class="ace_layer ace_text-layer"]')[0]
|
|
|
|
editlines = editfield.xpath('/div[@class="ace_line"]')
|
|
|
|
rawlines = []
|
|
|
|
|
|
|
|
for line in editlines:
|
|
|
|
rawlines.append(line.text)
|
|
|
|
return rawlines
|
|
|
|
|
|
|
|
@text.setter
|
2021-10-14 18:41:57 +04:00
|
|
|
def text(self, value:Union[str,bytes]) -> None:
|
2021-10-14 17:56:01 +04:00
|
|
|
self.atserv.atserver_request(
|
|
|
|
f'https://aternos.org/panel/ajax/save.php',
|
|
|
|
atconnect.REQPOST, data={'content': value},
|
|
|
|
sendtoken=True
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
2021-10-14 18:41:57 +04:00
|
|
|
def name(self) -> str:
|
2021-10-14 17:56:01 +04:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
2021-10-14 18:41:57 +04:00
|
|
|
def ftype(self) -> int:
|
2021-10-14 17:56:01 +04:00
|
|
|
return self._ftype
|
|
|
|
|
|
|
|
@property
|
2021-10-14 18:41:57 +04:00
|
|
|
def size(self) -> float:
|
2021-10-14 17:56:01 +04:00
|
|
|
return self._size
|