Remove global cookie checking
This commit is contained in:
parent
59b8c629d7
commit
413707950e
2 changed files with 1 additions and 134 deletions
|
|
@ -47,7 +47,6 @@ from .Utils import (
|
||||||
get_file_sidecar,
|
get_file_sidecar,
|
||||||
get_files,
|
get_files,
|
||||||
get_mime_type,
|
get_mime_type,
|
||||||
load_cookies,
|
|
||||||
read_logfile,
|
read_logfile,
|
||||||
validate_url,
|
validate_url,
|
||||||
validate_uuid,
|
validate_uuid,
|
||||||
|
|
@ -1698,103 +1697,6 @@ class HttpAPI(Common):
|
||||||
LOG.exception(e)
|
LOG.exception(e)
|
||||||
return web.json_response(data={"error": str(e)}, status=web.HTTPInternalServerError.status_code)
|
return web.json_response(data={"error": str(e)}, status=web.HTTPInternalServerError.status_code)
|
||||||
|
|
||||||
@route("GET", "api/youtube/auth")
|
|
||||||
async def is_authenticated(self, _: Request) -> Response:
|
|
||||||
"""
|
|
||||||
Check if the user cookies are valid.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (Request): The request object.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Response: The response object
|
|
||||||
|
|
||||||
"""
|
|
||||||
ytdlp_args = self.config.get_ytdlp_args()
|
|
||||||
|
|
||||||
c_request = {}
|
|
||||||
c_request_file = os.path.join(self.config.config_path, "check_cookie_request.json")
|
|
||||||
if os.path.exists(c_request_file):
|
|
||||||
async with await anyio.open_file(c_request_file, "r", encoding="utf-8") as f:
|
|
||||||
try:
|
|
||||||
c_request = json.loads(await f.read())
|
|
||||||
except json.JSONDecodeError as e:
|
|
||||||
LOG.error(f"Failed to load '{c_request_file}'. '{e!s}'.")
|
|
||||||
LOG.exception(e)
|
|
||||||
return web.json_response(
|
|
||||||
data={"message": "Failed to load cookie request file. Check logs for more details."},
|
|
||||||
status=web.HTTPInternalServerError.status_code,
|
|
||||||
)
|
|
||||||
|
|
||||||
cookie_file = c_request.get("cookie_file", None)
|
|
||||||
if not cookie_file:
|
|
||||||
cookie_file = ytdlp_args.get("cookiefile", None)
|
|
||||||
if not cookie_file:
|
|
||||||
return web.json_response(
|
|
||||||
data={"message": "No cookie file provided."}, status=web.HTTPNotFound.status_code
|
|
||||||
)
|
|
||||||
|
|
||||||
if not os.path.exists(cookie_file):
|
|
||||||
return web.json_response(
|
|
||||||
data={"message": f"Cookie file '{cookie_file}' does not exist."}, status=web.HTTPNotFound.status_code
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
_, cookies = load_cookies(cookie_file)
|
|
||||||
except ValueError as e:
|
|
||||||
LOG.error(f"Failed to load cookies from '{cookie_file}'. '{e!s}'.")
|
|
||||||
LOG.exception(e)
|
|
||||||
return web.json_response(
|
|
||||||
data={"message": "Failed to load cookies. Check logs for more details."},
|
|
||||||
status=web.HTTPInternalServerError.status_code,
|
|
||||||
)
|
|
||||||
|
|
||||||
url = c_request.get("url", "https://www.youtube.com/paid_memberships")
|
|
||||||
|
|
||||||
try:
|
|
||||||
opts = {}
|
|
||||||
if c_request.get("proxy"):
|
|
||||||
opts["proxy"] = c_request.get("proxy")
|
|
||||||
|
|
||||||
try:
|
|
||||||
c_status = c_request.get("status", [200])
|
|
||||||
if isinstance(c_status, int):
|
|
||||||
c_status = [c_status]
|
|
||||||
if not isinstance(c_status, list):
|
|
||||||
c_status = [200]
|
|
||||||
except Exception:
|
|
||||||
c_status = [200]
|
|
||||||
|
|
||||||
async with httpx.AsyncClient(**opts) as client:
|
|
||||||
if "user-agent" in client.headers:
|
|
||||||
client.headers.pop("user-agent")
|
|
||||||
|
|
||||||
LOG.info(f"Checking '{url}' to validate if cookies are valid.")
|
|
||||||
response = await client.request(
|
|
||||||
method=c_request.get("method", "GET"),
|
|
||||||
url=url,
|
|
||||||
data=c_request.get("data", None),
|
|
||||||
json=c_request.get("json", None),
|
|
||||||
params=c_request.get("params", None),
|
|
||||||
headers=c_request.get("headers", None),
|
|
||||||
cookies=cookies,
|
|
||||||
follow_redirects=bool(c_request.get("follow_redirects", False)),
|
|
||||||
)
|
|
||||||
|
|
||||||
valid = response.status_code in c_status
|
|
||||||
|
|
||||||
return web.json_response(
|
|
||||||
data={"message": "Authenticated." if valid else "Not authenticated."},
|
|
||||||
status=web.HTTPOk.status_code if valid else web.HTTPUnauthorized.status_code,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"Failed to request '{url}'. '{e!s}'.")
|
|
||||||
LOG.exception(e)
|
|
||||||
return web.json_response(
|
|
||||||
data={"message": "Failed to check cookies status. Check logs for more details."},
|
|
||||||
status=web.HTTPInternalServerError.status_code,
|
|
||||||
)
|
|
||||||
|
|
||||||
@route("GET", "api/notifications")
|
@route("GET", "api/notifications")
|
||||||
async def notifications(self, _: Request) -> Response:
|
async def notifications(self, _: Request) -> Response:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,7 @@
|
||||||
|
|
||||||
<div class="is-pulled-right" v-if="socket.isConnected && false === config.app.basic_mode">
|
<div class="is-pulled-right" v-if="socket.isConnected && false === config.app.basic_mode">
|
||||||
<div class="field is-grouped">
|
<div class="field is-grouped">
|
||||||
<p class="control" v-if="config.app.has_cookies">
|
<p class="control" v-if="!config.app.basic_mode">
|
||||||
<button class="button is-purple" @click="checkCookies" v-tooltip.bottom="'Check youtube cookies status.'"
|
|
||||||
:disabled="isChecking">
|
|
||||||
<span class="icon"><i class="fas fa-cookie" :class="{ 'is-loading': isChecking }" /></span>
|
|
||||||
</button>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="control">
|
|
||||||
<button class="button is-warning" @click="pauseDownload" v-if="false === config.paused"
|
<button class="button is-warning" @click="pauseDownload" v-if="false === config.paused"
|
||||||
v-tooltip.bottom="'Pause non-active downloads.'">
|
v-tooltip.bottom="'Pause non-active downloads.'">
|
||||||
<span class="icon"><i class="fas fa-pause" /></span>
|
<span class="icon"><i class="fas fa-pause" /></span>
|
||||||
|
|
@ -63,15 +56,12 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { request } from '~/utils/index'
|
|
||||||
import { useStorage } from '@vueuse/core'
|
import { useStorage } from '@vueuse/core'
|
||||||
|
|
||||||
const emitter = defineEmits(['getInfo'])
|
const emitter = defineEmits(['getInfo'])
|
||||||
const config = useConfigStore()
|
const config = useConfigStore()
|
||||||
const stateStore = useStateStore()
|
const stateStore = useStateStore()
|
||||||
const socket = useSocketStore()
|
const socket = useSocketStore()
|
||||||
const toast = useToast()
|
|
||||||
const isChecking = ref(false)
|
|
||||||
const get_info = ref('')
|
const get_info = ref('')
|
||||||
const bg_enable = useStorage('random_bg', true)
|
const bg_enable = useStorage('random_bg', true)
|
||||||
const bg_opacity = useStorage('random_bg_opacity', 0.85)
|
const bg_opacity = useStorage('random_bg_opacity', 0.85)
|
||||||
|
|
@ -100,31 +90,6 @@ watch(() => stateStore.queue, () => {
|
||||||
useHead({ title: `YTPTube: ( ${Object.keys(stateStore.queue).length || 0}/${config.app.max_workers} | ${Object.keys(stateStore.history).length || 0} )` })
|
useHead({ title: `YTPTube: ( ${Object.keys(stateStore.queue).length || 0}/${config.app.max_workers} | ${Object.keys(stateStore.history).length || 0} )` })
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|
||||||
const checkCookies = async () => {
|
|
||||||
if (true === isChecking.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false === confirm(`Check for cookies status?`)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
isChecking.value = true
|
|
||||||
const response = await request('/api/youtube/auth')
|
|
||||||
const data = await response.json()
|
|
||||||
if (response.ok) {
|
|
||||||
toast.success('Succuss. ' + data.message)
|
|
||||||
} else {
|
|
||||||
toast.error('Failed. ' + data.message)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
toast.error('Failed to check cookies state. ' + e.message)
|
|
||||||
} finally {
|
|
||||||
isChecking.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const pauseDownload = () => {
|
const pauseDownload = () => {
|
||||||
if (false === confirm('Are you sure you want to pause all non-active downloads?')) {
|
if (false === confirm('Are you sure you want to pause all non-active downloads?')) {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue