mirror of
https://github.com/jorisbertomeu/web-screensaver.git
synced 2026-04-19 16:27:40 +02:00
Add collection ID from HA feat
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
export class PhotoController {
|
export class PhotoController {
|
||||||
constructor(db, photoService) {
|
constructor(db, photoService) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -13,12 +15,27 @@ export class PhotoController {
|
|||||||
return res.status(400).json({ error: 'Invalid settings' });
|
return res.status(400).json({ error: 'Invalid settings' });
|
||||||
}
|
}
|
||||||
|
|
||||||
let collections = settings.unsplash.collectionsId;
|
let collections = settings.unsplash?.HACollectionsId;
|
||||||
|
|
||||||
|
if (collections && collections.length > 0) {
|
||||||
|
const resp = await fetch(`${settings.hass.endpoint}/api/states/${collections}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${settings.hass.token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const data = await resp?.json();
|
||||||
|
collections = data.state;
|
||||||
|
if (collections.includes(',')) {
|
||||||
|
collections = collections.split(',');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
collections = settings.unsplash.collectionsId;
|
||||||
|
}
|
||||||
if (collections) {
|
if (collections) {
|
||||||
collections = Array.isArray(collections) ? collections : [collections];
|
collections = Array.isArray(collections) ? collections : [collections];
|
||||||
}
|
}
|
||||||
|
|
||||||
const photo = await this.photoService.pickPictureFromFile(collections, false, settings.unsplash);
|
const photo = await this.photoService.pickPictureFromFile(collections, true, settings.unsplash);
|
||||||
|
|
||||||
if (!photo) {
|
if (!photo) {
|
||||||
return res.status(500).json({ error: 'Failed to fetch photo' });
|
return res.status(500).json({ error: 'Failed to fetch photo' });
|
||||||
|
|||||||
@@ -55,6 +55,14 @@
|
|||||||
<span class="input-group-text"><i class="fa fa-layer-group"></i></span>
|
<span class="input-group-text"><i class="fa fa-layer-group"></i></span>
|
||||||
<input [(ngModel)]="settings.unsplash.collectionsId" type="text" class="form-control" placeholder="ex: 1806988,1427155">
|
<input [(ngModel)]="settings.unsplash.collectionsId" type="text" class="form-control" placeholder="ex: 1806988,1427155">
|
||||||
</div>
|
</div>
|
||||||
|
<label class="form-label">Unsplash Collections ID from HA Entity</label>
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text"><i class="fa fa-layer-group"></i></span>
|
||||||
|
<input [(ngModel)]="settings.unsplash.HACollectionsId" type="text" class="form-control" placeholder="ex: input_text.unsplash_collections">
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-primary">
|
||||||
|
You can <b>specify a Home Assistant entity</b> that contains the Unsplash Collections ID. This way you can <b>change the collections directly</b> from Home Assistant.<br>For example, you can use an <b>input_text entity</b> with the collections ID as the value separated by commas.<br><br>If you use this option, the collections ID field <b>will be ignored</b>.
|
||||||
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<button [disabled]="isSaving" (click)="saveSettings()" class="btn btn-primary float-end"><i class="fa fa-save me-2"></i>Save</button>
|
<button [disabled]="isSaving" (click)="saveSettings()" class="btn btn-primary float-end"><i class="fa fa-save me-2"></i>Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ export class AdminComponent implements OnInit {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
accessKey: '',
|
accessKey: '',
|
||||||
secretKey: '',
|
secretKey: '',
|
||||||
collectionsId: ''
|
collectionsId: '',
|
||||||
|
HACollectionsId: ''
|
||||||
},
|
},
|
||||||
hass: {
|
hass: {
|
||||||
endpoint: '',
|
endpoint: '',
|
||||||
@@ -49,7 +50,8 @@ export class AdminComponent implements OnInit {
|
|||||||
enabled: respJson?.unsplash?.enabled || false,
|
enabled: respJson?.unsplash?.enabled || false,
|
||||||
accessKey: respJson?.unsplash?.accessKey || '',
|
accessKey: respJson?.unsplash?.accessKey || '',
|
||||||
secretKey: respJson?.unsplash?.secretKey || '',
|
secretKey: respJson?.unsplash?.secretKey || '',
|
||||||
collectionsId: respJson?.unsplash?.collectionsId ? respJson?.unsplash?.collectionsId.join(',') : ''
|
collectionsId: respJson?.unsplash?.collectionsId ? respJson?.unsplash?.collectionsId.join(',') : '',
|
||||||
|
HACollectionsId: respJson?.unsplash?.HACollectionsId || ''
|
||||||
},
|
},
|
||||||
hass: {
|
hass: {
|
||||||
endpoint: respJson?.hass?.endpoint || '',
|
endpoint: respJson?.hass?.endpoint || '',
|
||||||
|
|||||||
Reference in New Issue
Block a user