Compare commits

...

2 commits

Author SHA1 Message Date
64559d3668
Added some try catch 2025-02-01 17:01:14 +02:00
37441d2dd4
Implement account/bittorrent settings 2025-02-01 16:59:26 +02:00
3 changed files with 144 additions and 44 deletions

View file

@ -29,9 +29,16 @@ def titles_route():
if image_cache: if image_cache:
titles[title]["image"] = image_cache.image titles[title]["image"] = image_cache.image
else: else:
toloka_torrent = config.toloka.get_torrent( try:
f"https://toloka.to/{titles[title]['guid']}" toloka_torrent = config.toloka.get_torrent(
) f"https://toloka.to/{titles[title]['guid']}"
)
except AttributeError as e:
print(f"https://toloka.to/{titles[title]['guid']}")
config.logger.warning(
f"Failed to get https://toloka.to/{titles[title]['guid']} torrent: {str(e)}"
)
pass
toloka_img = ( toloka_img = (
f"https:{toloka_torrent.img}" f"https:{toloka_torrent.img}"
if toloka_torrent.img.startswith("//") if toloka_torrent.img.startswith("//")

View file

@ -18,7 +18,7 @@
</article> </article>
<article class="primary-text"> <article class="primary-text">
<a class="row wave" @click="openDialog('login')"> <a class="row wave" @click="openDialog('username')">
<i>person</i> <i>person</i>
<div class="max"> <div class="max">
<h6 class="small">Логін</h6> <h6 class="small">Логін</h6>
@ -34,7 +34,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave" @click="openDialog('hub')"> <a class="row wave" @click="openDialog('client')">
<i>hub</i> <i>hub</i>
<div class="max"> <div class="max">
<h6 class="small">Торрент клієнт</h6> <h6 class="small">Торрент клієнт</h6>
@ -42,7 +42,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave" @click="openDialog('directory')"> <a class="row wave" @click="openDialog('default_download_dir')">
<i>description</i> <i>description</i>
<div class="max"> <div class="max">
<h6 class="small">Директорія завантажень</h6> <h6 class="small">Директорія завантажень</h6>
@ -50,7 +50,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave" @click="openDialog('delay')"> <a class="row wave" @click="openDialog('wait_time')">
<i>hourglass_top</i> <i>hourglass_top</i>
<div class="max"> <div class="max">
<h6 class="small">Затримка</h6> <h6 class="small">Затримка</h6>
@ -67,8 +67,8 @@
<form @submit.prevent="editTitle" class="grid"> <form @submit.prevent="editTitle" class="grid">
<div class="field label prefix border s12"> <div class="field label prefix border s12">
<i>folder</i> <i>folder</i>
<input type="text" v-model="dialogValue" placeholder="Назва директорії" required /> <input type="text" v-model="dialogValue" required />
<label>Назва директорії</label> <label>{{ fieldLabels[currentField] }}</label>
</div> </div>
<nav class="right-align small-padding s12"> <nav class="right-align small-padding s12">
<button class="border small-round" @click="closeDialog"> <button class="border small-round" @click="closeDialog">
@ -85,16 +85,32 @@
<script> <script>
import axios from 'axios'; import axios from 'axios';
export default { export default {
data() { data() {
return { return {
isDialogOpen: false, isDialogOpen: false,
dialogValue: '', dialogValue: '',
currentField: '' currentField: '',
config: {},
fieldLabels: {
username: 'Логін',
password: 'Пароль',
client: 'Торрент Клієнт',
default_download_dir: 'Директорія завантажень',
client_wait_time: 'Затримка'
},
}; };
}, },
created() {
async created() {
try {
// Fetch the current config from the server
const response = await axios.get('/api/config');
this.config = response.data;
} catch (error) {
console.error('Error fetching config:', error);
}
}, },
methods: { methods: {
@ -103,7 +119,7 @@ export default {
}, },
openDialog(field) { openDialog(field) {
this.currentField = field; this.currentField = field;
this.dialogValue = field; // очищаем значение при открытии диалога this.dialogValue = this.config.Toloka?.[field] || ''; // Prefill value if available
this.isDialogOpen = true; this.isDialogOpen = true;
}, },
closeDialog() { closeDialog() {
@ -111,37 +127,30 @@ export default {
}, },
async editTitle() { async editTitle() {
try { try {
// Здесь можно установить URL вашего API // Construct URL for the request
const response = await fetch(`https://your-api-endpoint/${this.currentField}`, { const url = `/api/config/Toloka/${this.currentField}/${encodeURIComponent(this.dialogValue)}`;
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
value: this.dialogValue
})
});
if (!response.ok) { // Send the request
throw new Error('Network response was not ok'); const response = await axios.get(url);
if (response.status !== 200) {
throw new Error('Server response error');
} }
const data = await response.json(); // Update local config
// Обработка ответа сервера (если необходимо) this.config.Toloka[this.currentField] = this.dialogValue;
console.log(data);
// Handle successful response
console.log('Successfully updated:', response.data);
this.closeDialog(); this.closeDialog();
} catch (error) { } catch (error) {
console.error('Ошибка:', error); console.error('Error:', error);
} }
},
goBack() {
this.$router.back();
} }
} }
} };
</script> </script>
<style scoped> <style scoped>
</style> </style>

View file

@ -19,7 +19,7 @@
<article class="primary-text"> <article class="primary-text">
<a class="row wave"> <a class="row wave" @click="openDialog('username')">
<i>person</i> <i>person</i>
<div class="max"> <div class="max">
<h6 class="small">Логін</h6> <h6 class="small">Логін</h6>
@ -27,7 +27,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave"> <a class="row wave" @click="openDialog('password')">
<i>password</i> <i>password</i>
<div class="max"> <div class="max">
<h6 class="small">Пароль</h6> <h6 class="small">Пароль</h6>
@ -35,7 +35,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave"> <a class="row wave" @click="openDialog('port')">
<i>lan</i> <i>lan</i>
<div class="max"> <div class="max">
<h6 class="small">Порт</h6> <h6 class="small">Порт</h6>
@ -43,7 +43,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave"> <a class="row wave" @click="openDialog('host')">
<i>link</i> <i>link</i>
<div class="max"> <div class="max">
<h6 class="small">IP/Домен</h6> <h6 class="small">IP/Домен</h6>
@ -51,7 +51,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave"> <a class="row wave" @click="openDialog('protocol')">
<i>http</i> <i>http</i>
<div class="max"> <div class="max">
<h6 class="small">Протокол</h6> <h6 class="small">Протокол</h6>
@ -59,7 +59,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave"> <a class="row wave" @click="openDialog('rpc')">
<i>api</i> <i>api</i>
<div class="max"> <div class="max">
<h6 class="small">RPC</h6> <h6 class="small">RPC</h6>
@ -67,7 +67,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave"> <a class="row wave" @click="openDialog('category')">
<i>category</i> <i>category</i>
<div class="max"> <div class="max">
<h6 class="small">Категорія</h6> <h6 class="small">Категорія</h6>
@ -75,7 +75,7 @@
</div> </div>
</a> </a>
<hr> <hr>
<a class="row wave"> <a class="row wave" @click="openDialog('tag')">
<i>tag</i> <i>tag</i>
<div class="max"> <div class="max">
<h6 class="small">Тег</h6> <h6 class="small">Тег</h6>
@ -87,24 +87,108 @@
<hr> <hr>
</article> </article>
<dialog :class="{ 'active': isDialogOpen }">
<h5 class="primary-text">Edit</h5>
<form @submit.prevent="editField" class="grid">
<div class="field label prefix border s12">
<i>folder</i>
<input type="text" v-model="dialogValue" :placeholder="fieldPlaceholders[currentField]" required />
<label>{{ fieldLabels[currentField] }}</label>
</div>
<nav class="right-align small-padding s12">
<button class="border small-round" @click="closeDialog">
<i>cancel</i>
</button>
<button class="border small-round" type="submit">
<i>edit</i>
</button>
</nav>
</form>
</dialog>
</template> </template>
<script> <script>
import axios from 'axios'; import axios from 'axios';
export default { export default {
data() { data() {
return { return {
isDialogOpen: false,
dialogValue: '',
currentField: '',
config: {},
fieldLabels: {
username: 'Username',
password: 'Password',
port: 'Port',
host: 'IP/Domain',
protocol: 'Protocol',
rpc: 'RPC',
category: 'Category',
tag: 'Tag'
},
fieldPlaceholders: {
username: 'Enter your username',
password: 'Enter your password',
port: 'Enter port number',
host: 'Enter IP or domain',
protocol: 'Enter protocol (e.g., HTTP)',
rpc: 'Enter RPC path (default: /transmission/rpc)',
category: 'Enter category name',
tag: 'Enter torrent tag'
}
}; };
}, },
created() {
async created() {
try {
// Fetch the current configuration from the server
const response = await axios.get('/api/config');
this.config = response.data;
} catch (error) {
console.error('Error fetching config:', error);
}
}, },
methods: { methods: {
goBack() { goBack() {
this.$router.back(); this.$router.back();
},
openDialog(field) {
this.currentField = field;
this.dialogValue = this.config.transmission?.[field] || ''; // Pre-fill value if available
this.isDialogOpen = true;
},
closeDialog() {
this.isDialogOpen = false;
},
async editField() {
try {
// Construct URL for the API request
const url = `/api/config/transmission/${this.currentField}/${encodeURIComponent(this.dialogValue)}`;
// Send the update request
const response = await axios.post(url);
if (response.status !== 200) {
throw new Error('Server response error');
}
// Update local configuration
this.config.transmission[this.currentField] = this.dialogValue;
// Log success message
console.log('Successfully updated:', response.data);
this.closeDialog();
} catch (error) {
console.error('Error:', error);
}
} }
} }
} };
</script> </script>
<style scoped>
</style>