Skip to content

Commit d2f00f5

Browse files
committed
Refactor .gitignore and settings.py files
1 parent b73f2d9 commit d2f00f5

File tree

4 files changed

+127
-13
lines changed

4 files changed

+127
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ example/
66
__pycache__/
77
*.py[cod]
88
*$py.class
9+
config/
910

1011
# C extensions
1112
*.so

stream_fusion/static/config.js

+89
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,94 @@ function resetAuthButton() {
134134
button.classList.remove('opacity-50', 'cursor-not-allowed');
135135
}
136136

137+
function startADAuth() {
138+
document.getElementById('ad-auth-button').disabled = true;
139+
document.getElementById('ad-auth-button').textContent = "Authentication in progress...";
140+
141+
console.log('Starting AllDebrid authentication');
142+
fetch('/api/auth/alldebrid/pin/get', {
143+
method: 'GET',
144+
headers: {
145+
'Content-Type': 'application/json'
146+
}
147+
})
148+
.then(response => {
149+
console.log('Response received', response);
150+
if (!response.ok) {
151+
throw new Error('Request error');
152+
}
153+
return response.json();
154+
})
155+
.then(data => {
156+
console.log('Data received:', data);
157+
document.getElementById('ad-verification-url').href = data.data.user_url;
158+
document.getElementById('ad-verification-url').textContent = data.data.base_url;
159+
document.getElementById('ad-user-code').textContent = data.data.pin;
160+
document.getElementById('ad-auth-instructions').style.display = 'block';
161+
pollForADCredentials(data.data.check, data.data.pin, data.data.expires_in);
162+
})
163+
.catch(error => {
164+
console.error('Detailed error:', error);
165+
alert("Authentication error. Please try again.");
166+
resetADAuthButton();
167+
});
168+
}
169+
170+
function pollForADCredentials(check, pin, expiresIn) {
171+
console.log('Starting polling with check:', check);
172+
const pollInterval = setInterval(() => {
173+
fetch(`/api/auth/alldebrid/pin/check?agent=streamfusion&check=${encodeURIComponent(check)}&pin=${encodeURIComponent(pin)}`, {
174+
method: 'GET',
175+
headers: {
176+
'accept': 'application/json'
177+
}
178+
})
179+
.then(response => {
180+
if (response.status === 400) {
181+
console.log('Waiting for user authorization...');
182+
return null;
183+
}
184+
if (!response.ok) {
185+
throw new Error('Request error');
186+
}
187+
return response.json();
188+
})
189+
.then(data => {
190+
if (data === null) return; // Skip processing if user hasn't entered PIN yet
191+
console.log('Poll response:', data);
192+
if (data.data && data.data.activated && data.data.apikey) {
193+
clearInterval(pollInterval);
194+
clearTimeout(timeoutId);
195+
document.getElementById('ad_token_info').value = data.data.apikey;
196+
document.getElementById('ad-auth-status').style.display = 'block';
197+
document.getElementById('ad-auth-instructions').style.display = 'none';
198+
document.getElementById('ad-auth-button').disabled = true;
199+
document.getElementById('ad-auth-button').textContent = "Connection successful";
200+
console.log('AllDebrid authentication successful');
201+
} else {
202+
console.log('Waiting for user authorization...');
203+
}
204+
})
205+
.catch(error => {
206+
console.error('Error:', error);
207+
console.log('Next attempt in 5 seconds...');
208+
});
209+
}, 5000);
210+
211+
const timeoutId = setTimeout(() => {
212+
clearInterval(pollInterval);
213+
alert("Authentication timeout. Please try again.");
214+
resetADAuthButton();
215+
}, expiresIn * 1000);
216+
}
217+
218+
function resetADAuthButton() {
219+
const button = document.getElementById('ad-auth-button');
220+
button.disabled = false;
221+
button.textContent = "Connect with AllDebrid";
222+
console.log('AllDebrid auth button reset');
223+
}
224+
137225
function handleUniqueAccounts() {
138226
const rdCheckbox = document.getElementById('debrid_rd');
139227
const adCheckbox = document.getElementById('debrid_ad');
@@ -195,6 +283,7 @@ function loadData() {
195283
document.getElementById('yggflix').checked = decodedData.yggflix;
196284
document.getElementById('sharewood').checked = decodedData.sharewood;
197285
document.getElementById('rd_token_info').value = decodedData.RDToken;
286+
document.getElementById('ad_token_info').value = decodedData.ADToken;
198287
document.getElementById('sharewoodPasskey').value = decodedData.sharewoodPasskey;
199288
document.getElementById('yggPasskey').value = decodedData.yggPasskey;
200289
document.getElementById('ApiKey').value = decodedData.apiKey;

stream_fusion/static/index.html

+10-12
Original file line numberDiff line numberDiff line change
@@ -256,28 +256,26 @@ <h2 class="text-white font-semibold leading-7">Real-Debrid Configuration</h2>
256256
<div class="border-b border-gray-900/10 dark:border-white/50 pb-12">
257257
<h2 class="text-white font-semibold leading-7">AllDebrid Configuration</h2>
258258
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
259-
<!-- <div class="sm:col-span-3">
260-
<button id="rd-auth-button" onclick="startRealDebridAuth()"
259+
<div class="sm:col-span-3">
260+
<button id="ad-auth-button" onclick="startADAuth()"
261261
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
262-
S'authentifier avec Real-Debrid
262+
S'authentifier avec AllDebrid
263263
</button>
264-
<div id="auth-instructions" class="mt-2 text-sm text-gray-600 dark:text-gray-400"
264+
<div id="ad-auth-instructions" class="mt-2 text-sm text-gray-600 dark:text-gray-400"
265265
style="display: none;">
266-
Veuillez vous rendre sur <a id="verification-url"
267-
class="text-blue-500 hover:underline" target="_blank"></a>
268-
: Votre user code est : <span id="user-code"></span>
266+
Veuillez entrer ce code PIN sur le site AllDebrid : <span id="ad-user-code"></span><br>
267+
Visitez <a id="ad-verification-url" class="text-blue-500 hover:underline" target="_blank"></a>
269268
</div>
270-
<div id="auth-status" class="mt-2 text-sm text-green-600 dark:text-green-400"
269+
<div id="ad-auth-status" class="mt-2 text-sm text-green-600 dark:text-green-400"
271270
style="display: none;">
272271
Authentification réussie !
273272
</div>
274273
</div>
275274
<div class="sm:col-span-3">
276-
<textarea id="rd_token_info" rows="4"
277-
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
275+
<textarea id="ad_token_info" rows="2"
276+
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 p-2"
278277
readonly></textarea>
279-
</div> -->
280-
<!-- AllDebrid not implemented yet -->
278+
</div>
281279
</div>
282280
</div>
283281
</div>

stream_fusion/web/api/auth/views.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timezone
22
from typing import List, Optional
33
from uuid import UUID
4+
import aiohttp
45
from fastapi import APIRouter, Depends, HTTPException, Query
56

67
from stream_fusion.services.postgresql.dao.apikey_dao import APIKeyDAO
@@ -249,4 +250,29 @@ async def get_token(client_id: str, client_secret: str, device_code: str):
249250
logger.info(f"Requesting token for device code: {device_code}")
250251
results = await rd_service.get_token(client_id, client_secret, device_code)
251252
logger.info("Token received successfully")
252-
return results
253+
return results
254+
255+
256+
@router.get("/alldebrid/pin/get")
257+
async def get_alldebrid_pin():
258+
logger.info("Requesting PIN code for AllDebrid")
259+
async with aiohttp.ClientSession() as session:
260+
async with session.get(f"https://api.alldebrid.com/v4/pin/get?agent={settings.ad_user_app}") as response:
261+
if response.status != 200:
262+
logger.error(f"Error retrieving AllDebrid PIN: {response.status}")
263+
raise HTTPException(status_code=response.status, detail="Error retrieving AllDebrid PIN")
264+
data = await response.json()
265+
logger.info("AllDebrid PIN code received successfully")
266+
return data
267+
268+
@router.get("/alldebrid/pin/check")
269+
async def check_alldebrid_pin(check: str, pin: str):
270+
logger.info(f"Verifying AllDebrid PIN code: {pin}")
271+
async with aiohttp.ClientSession() as session:
272+
async with session.get(f"https://api.alldebrid.com/v4/pin/check?check={check}&pin={pin}&agent={settings.ad_user_app}") as response:
273+
if response.status != 200:
274+
logger.error(f"Error verifying AllDebrid PIN: {response.status}")
275+
raise HTTPException(status_code=response.status, detail="Error verifying AllDebrid PIN")
276+
data = await response.json()
277+
logger.info("AllDebrid PIN code verification successful")
278+
return data

0 commit comments

Comments
 (0)