mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
correct exeption and double daeomon use
This commit is contained in:
parent
7fa30db647
commit
479d4ec654
7
supysonic/api/exceptions.py
Normal file → Executable file
7
supysonic/api/exceptions.py
Normal file → Executable file
@ -122,10 +122,3 @@ class AggregateException(SubsonicAPIException):
|
|||||||
)
|
)
|
||||||
# rv.status_code = self.code
|
# rv.status_code = self.code
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
class DaemonUnavailable(SubsonicAPIException):
|
|
||||||
code = 404
|
|
||||||
api_code = 80
|
|
||||||
message = (
|
|
||||||
"Supysonic Daemon not running on this server."
|
|
||||||
)
|
|
45
supysonic/api/scan.py
Normal file → Executable file
45
supysonic/api/scan.py
Normal file → Executable file
@ -1,33 +1,42 @@
|
|||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
from functools import wraps
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from .user import admin_only
|
from .user import admin_only
|
||||||
from .exceptions import Forbidden,DaemonUnavailable,ServerError
|
from .exceptions import ServerError
|
||||||
from ..db import Folder
|
|
||||||
from ..daemon.client import DaemonClient
|
from ..daemon.client import DaemonClient
|
||||||
from ..daemon.exceptions import DaemonUnavailableError
|
|
||||||
from ..managers.folder import FolderManager
|
|
||||||
|
|
||||||
@api.route("/startScan.view", methods=["GET", "POST"])
|
@api.route("/startScan.view", methods=["GET", "POST"])
|
||||||
@admin_only
|
@admin_only
|
||||||
def startScan():
|
def startScan():
|
||||||
try:
|
try:
|
||||||
DaemonClient(current_app.config["DAEMON"]["socket"]).scan()
|
daeomonclient = DaemonClient(current_app.config["DAEMON"]["socket"])
|
||||||
except ValueError as e:
|
daeomonclient.scan()
|
||||||
ServerError(str(e))
|
scanned = daeomonclient.get_scanning_progress()
|
||||||
except DaemonUnavailableError:
|
except Exception as e:
|
||||||
raise DaemonUnavailable()
|
raise ServerError(str(e))
|
||||||
return getScanStatus()
|
return request.formatter(
|
||||||
|
"scanStatus",
|
||||||
|
dict(
|
||||||
|
scanning="true" if scanned is not None else "false",
|
||||||
|
count=scanned if scanned is not None else 0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@api.route("/getScanStatus.view", methods=["GET", "POST"])
|
@api.route("/getScanStatus.view", methods=["GET", "POST"])
|
||||||
@admin_only
|
@admin_only
|
||||||
def getScanStatus():
|
def getScanStatus():
|
||||||
try:
|
try:
|
||||||
scanned=DaemonClient(current_app.config["DAEMON"]["socket"]).get_scanning_progress()
|
scanned = DaemonClient(
|
||||||
except DaemonUnavailableError:
|
current_app.config["DAEMON"]["socket"]
|
||||||
raise DaemonUnavailable()
|
).get_scanning_progress()
|
||||||
return request.formatter("scanStatus",
|
except Exception as e:
|
||||||
dict(scanning='true' if scanned is not None else 'false',
|
raise ServerError(str(e))
|
||||||
count= scanned if scanned is not None else 0))
|
return request.formatter(
|
||||||
|
"scanStatus",
|
||||||
|
dict(
|
||||||
|
scanning="true" if scanned is not None else "false",
|
||||||
|
count=scanned if scanned is not None else 0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user