2020-04-14 11:13:45 +00:00
|
|
|
|
import RestModel from "model/rest";
|
2019-05-09 04:48:10 +00:00
|
|
|
|
import Api from "common/api";
|
2020-01-23 23:45:59 +00:00
|
|
|
|
import {DateTime} from "luxon";
|
2020-05-14 09:57:26 +00:00
|
|
|
|
import Util from "common/util";
|
2020-05-27 17:38:40 +00:00
|
|
|
|
import {config} from "../session";
|
2020-05-28 13:12:18 +00:00
|
|
|
|
import countries from "resources/countries.json";
|
2018-08-07 18:17:14 +00:00
|
|
|
|
|
2020-05-22 14:29:12 +00:00
|
|
|
|
export const SrcManual = "manual";
|
|
|
|
|
export const CodecAvc1 = "avc1";
|
|
|
|
|
export const TypeMP4 = "mp4";
|
|
|
|
|
export const TypeJpeg = "jpg";
|
2020-05-23 18:58:58 +00:00
|
|
|
|
export const TypeImage = "image";
|
2020-05-22 14:29:12 +00:00
|
|
|
|
export const YearUnknown = -1;
|
|
|
|
|
export const MonthUnknown = -1;
|
2020-04-18 21:20:54 +00:00
|
|
|
|
|
2020-05-22 14:29:12 +00:00
|
|
|
|
export class Photo extends RestModel {
|
2020-01-23 23:45:59 +00:00
|
|
|
|
getDefaults() {
|
|
|
|
|
return {
|
2020-05-27 11:40:21 +00:00
|
|
|
|
DocumentID: "",
|
2020-05-23 18:58:58 +00:00
|
|
|
|
UID: "",
|
|
|
|
|
Type: TypeImage,
|
|
|
|
|
Favorite: false,
|
|
|
|
|
Private: false,
|
2020-01-23 23:45:59 +00:00
|
|
|
|
TakenAt: "",
|
2020-04-18 21:20:54 +00:00
|
|
|
|
TakenAtLocal: "",
|
|
|
|
|
TakenSrc: "",
|
|
|
|
|
TimeZone: "",
|
2020-05-23 18:58:58 +00:00
|
|
|
|
Path: "",
|
|
|
|
|
Color: "",
|
|
|
|
|
Name: "",
|
|
|
|
|
Title: "",
|
2020-04-18 21:20:54 +00:00
|
|
|
|
TitleSrc: "",
|
2020-05-23 18:58:58 +00:00
|
|
|
|
Description: "",
|
2020-05-18 20:18:58 +00:00
|
|
|
|
DescriptionSrc: "",
|
2020-05-23 18:58:58 +00:00
|
|
|
|
Resolution: 0,
|
|
|
|
|
Quality: 0,
|
|
|
|
|
Lat: 0.0,
|
|
|
|
|
Lng: 0.0,
|
|
|
|
|
Altitude: 0,
|
|
|
|
|
Iso: 0,
|
|
|
|
|
FocalLength: 0,
|
|
|
|
|
FNumber: 0.0,
|
|
|
|
|
Exposure: "",
|
|
|
|
|
Views: 0,
|
2020-01-23 23:45:59 +00:00
|
|
|
|
Camera: {},
|
|
|
|
|
CameraID: 0,
|
2020-04-18 21:20:54 +00:00
|
|
|
|
CameraSrc: "",
|
2020-01-23 23:45:59 +00:00
|
|
|
|
Lens: {},
|
|
|
|
|
LensID: 0,
|
2020-05-23 18:58:58 +00:00
|
|
|
|
Country: "",
|
|
|
|
|
Year: YearUnknown,
|
|
|
|
|
Month: MonthUnknown,
|
2020-05-18 20:18:58 +00:00
|
|
|
|
Details: {
|
|
|
|
|
Keywords: "",
|
|
|
|
|
Notes: "",
|
|
|
|
|
Subject: "",
|
|
|
|
|
Artist: "",
|
|
|
|
|
Copyright: "",
|
|
|
|
|
License: "",
|
2020-03-26 08:41:33 +00:00
|
|
|
|
},
|
2020-01-23 23:45:59 +00:00
|
|
|
|
Files: [],
|
|
|
|
|
Labels: [],
|
|
|
|
|
Keywords: [],
|
|
|
|
|
Albums: [],
|
2020-04-08 11:24:06 +00:00
|
|
|
|
Links: [],
|
2020-05-29 10:56:24 +00:00
|
|
|
|
Location: {},
|
|
|
|
|
Place: {},
|
|
|
|
|
PlaceID: "",
|
|
|
|
|
LocationID: "",
|
2020-05-25 17:10:44 +00:00
|
|
|
|
LocSrc: "",
|
|
|
|
|
// Additional data in result lists.
|
2020-05-23 18:58:58 +00:00
|
|
|
|
LocLabel: "",
|
|
|
|
|
LocCity: "",
|
|
|
|
|
LocState: "",
|
|
|
|
|
LocCountry: "",
|
|
|
|
|
FileUID: "",
|
2020-05-24 20:16:06 +00:00
|
|
|
|
FileRoot: "",
|
2020-05-23 18:58:58 +00:00
|
|
|
|
FileName: "",
|
|
|
|
|
Hash: "",
|
|
|
|
|
Width: "",
|
|
|
|
|
Height: "",
|
2020-05-25 17:10:44 +00:00
|
|
|
|
// Date fields.
|
|
|
|
|
CreatedAt: "",
|
|
|
|
|
UpdatedAt: "",
|
|
|
|
|
DeletedAt: null,
|
2020-01-23 23:45:59 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 20:16:06 +00:00
|
|
|
|
baseName(truncate) {
|
2020-05-25 17:10:44 +00:00
|
|
|
|
let result = this.fileBase(this.FileName ? this.FileName : this.mainFile().Name);
|
2020-05-24 20:16:06 +00:00
|
|
|
|
|
2020-05-25 17:10:44 +00:00
|
|
|
|
if (truncate) {
|
|
|
|
|
result = Util.truncate(result, truncate, "...");
|
2020-05-24 20:16:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 17:10:44 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileBase(name) {
|
|
|
|
|
let result = name;
|
|
|
|
|
const slash = result.lastIndexOf("/");
|
|
|
|
|
|
|
|
|
|
if (slash >= 0) {
|
|
|
|
|
result = name.substring(slash + 1);
|
2020-05-24 20:16:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 17:10:44 +00:00
|
|
|
|
return result;
|
2020-05-24 20:16:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 18:17:14 +00:00
|
|
|
|
getEntityName() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return this.Title;
|
2018-08-07 18:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getId() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return this.UID;
|
2018-08-07 18:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-08 02:37:45 +00:00
|
|
|
|
getTitle() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return this.Title;
|
2019-04-26 00:22:53 +00:00
|
|
|
|
}
|
2019-04-18 15:27:08 +00:00
|
|
|
|
|
2018-08-09 21:10:05 +00:00
|
|
|
|
getGoogleMapsLink() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return "https://www.google.com/maps/place/" + this.Lat + "," + this.Lng;
|
2018-08-09 21:10:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 00:33:04 +00:00
|
|
|
|
refreshFileAttr() {
|
2020-04-23 09:00:29 +00:00
|
|
|
|
const file = this.mainFile();
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (!file || !file.Hash) {
|
2020-01-31 14:29:06 +00:00
|
|
|
|
return;
|
2020-01-24 00:33:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
this.Hash = file.Hash;
|
|
|
|
|
this.Width = file.Width;
|
|
|
|
|
this.Height = file.Height;
|
2020-04-23 09:00:29 +00:00
|
|
|
|
}
|
2020-01-24 00:33:04 +00:00
|
|
|
|
|
2020-05-15 07:39:32 +00:00
|
|
|
|
isPlayable() {
|
2020-05-14 17:03:12 +00:00
|
|
|
|
if (!this.Files) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return this.Files.findIndex(f => f.Codec === CodecAvc1) !== -1 || this.Files.findIndex(f => f.Type === TypeMP4) !== -1;
|
2020-05-14 17:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 13:36:42 +00:00
|
|
|
|
videoFile() {
|
|
|
|
|
if (!this.Files) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
let file = this.Files.find(f => f.Codec === CodecAvc1);
|
2020-05-15 07:39:32 +00:00
|
|
|
|
|
|
|
|
|
if (!file) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
file = this.Files.find(f => f.Type === TypeMP4);
|
2020-05-15 07:39:32 +00:00
|
|
|
|
}
|
2020-05-13 13:36:42 +00:00
|
|
|
|
|
|
|
|
|
if (!file) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
file = this.Files.find(f => !!f.Video);
|
2020-05-13 13:36:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 11:26:28 +00:00
|
|
|
|
videoUrl() {
|
2020-05-14 10:11:04 +00:00
|
|
|
|
const file = this.videoFile();
|
2020-05-13 13:36:42 +00:00
|
|
|
|
|
|
|
|
|
if (!file) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 17:56:56 +00:00
|
|
|
|
return `/api/v1/videos/${file.Hash}/${config.previewToken()}/${TypeMP4}`;
|
2020-05-13 13:36:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 09:00:29 +00:00
|
|
|
|
mainFile() {
|
|
|
|
|
if (!this.Files) {
|
|
|
|
|
return false;
|
2020-01-24 00:33:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
let file = this.Files.find(f => !!f.Primary);
|
2020-04-23 09:00:29 +00:00
|
|
|
|
|
|
|
|
|
if (!file) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
file = this.Files.find(f => f.Type === TypeJpeg);
|
2020-04-23 09:00:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return file;
|
2018-09-24 09:27:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 09:00:29 +00:00
|
|
|
|
mainFileHash() {
|
2020-04-21 14:34:43 +00:00
|
|
|
|
if (this.Files) {
|
2020-04-23 09:00:29 +00:00
|
|
|
|
let file = this.mainFile();
|
2020-04-21 14:34:43 +00:00
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (file && file.Hash) {
|
|
|
|
|
return file.Hash;
|
2020-04-21 14:34:43 +00:00
|
|
|
|
}
|
2020-05-23 18:58:58 +00:00
|
|
|
|
} else if (this.Hash) {
|
|
|
|
|
return this.Hash;
|
2020-04-21 14:34:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 12:30:28 +00:00
|
|
|
|
return "";
|
2020-04-21 14:34:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 11:26:28 +00:00
|
|
|
|
thumbnailUrl(type) {
|
2020-04-23 09:00:29 +00:00
|
|
|
|
let hash = this.mainFileHash();
|
2020-04-21 14:34:43 +00:00
|
|
|
|
|
|
|
|
|
if (!hash) {
|
2020-05-16 15:07:44 +00:00
|
|
|
|
let video = this.videoFile();
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (video && video.Hash) {
|
2020-05-27 17:56:56 +00:00
|
|
|
|
return `/api/v1/t/${video.Hash}/${config.previewToken()}/${type}`;
|
2020-05-16 15:07:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 14:34:43 +00:00
|
|
|
|
return "/api/v1/svg/photo";
|
2020-01-23 23:45:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 17:56:56 +00:00
|
|
|
|
return `/api/v1/t/${hash}/${config.previewToken()}/${type}`;
|
2020-01-23 23:45:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 16:16:35 +00:00
|
|
|
|
getDownloadUrl() {
|
2020-05-27 17:38:40 +00:00
|
|
|
|
return `/api/v1/dl/${this.mainFileHash()}?t=${config.downloadToken()}`;
|
2019-05-14 16:16:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 17:10:44 +00:00
|
|
|
|
downloadAll() {
|
|
|
|
|
if (!this.Files) {
|
2020-05-27 17:38:40 +00:00
|
|
|
|
let link = document.createElement("a");
|
|
|
|
|
link.href = `/api/v1/dl/${this.mainFileHash()}?t=${config.downloadToken()}`;
|
2020-05-25 17:10:44 +00:00
|
|
|
|
link.download = this.baseName(false);
|
|
|
|
|
link.click();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Files.forEach((file) => {
|
|
|
|
|
if (!file || !file.Hash) {
|
2020-05-27 17:38:40 +00:00
|
|
|
|
console.warn("no file hash found for download", file);
|
|
|
|
|
return;
|
2020-05-25 17:10:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-27 17:38:40 +00:00
|
|
|
|
let link = document.createElement("a");
|
|
|
|
|
link.href = `/api/v1/dl/${file.Hash}?t=${config.downloadToken()}`;
|
2020-05-25 17:10:44 +00:00
|
|
|
|
link.download = this.fileBase(file.Name);
|
|
|
|
|
link.click();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 11:26:28 +00:00
|
|
|
|
thumbnailSrcset() {
|
2018-09-24 17:07:43 +00:00
|
|
|
|
const result = [];
|
|
|
|
|
|
2020-05-21 11:26:28 +00:00
|
|
|
|
result.push(this.thumbnailUrl("fit_720") + " 720w");
|
|
|
|
|
result.push(this.thumbnailUrl("fit_1280") + " 1280w");
|
|
|
|
|
result.push(this.thumbnailUrl("fit_1920") + " 1920w");
|
|
|
|
|
result.push(this.thumbnailUrl("fit_2560") + " 2560w");
|
|
|
|
|
result.push(this.thumbnailUrl("fit_3840") + " 3840w");
|
2018-09-24 17:07:43 +00:00
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
|
return result.join(", ");
|
2018-09-24 17:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 14:04:17 +00:00
|
|
|
|
calculateSize(width, height) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (width >= this.Width && height >= this.Height) { // Smaller
|
|
|
|
|
return {width: this.Width, height: this.Height};
|
2019-05-13 16:01:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
const srcAspectRatio = this.Width / this.Height;
|
2019-05-14 14:04:17 +00:00
|
|
|
|
const maxAspectRatio = width / height;
|
|
|
|
|
|
|
|
|
|
let newW, newH;
|
|
|
|
|
|
|
|
|
|
if (srcAspectRatio > maxAspectRatio) {
|
|
|
|
|
newW = width;
|
|
|
|
|
newH = Math.round(newW / srcAspectRatio);
|
|
|
|
|
|
2019-05-13 16:01:50 +00:00
|
|
|
|
} else {
|
2019-05-14 14:04:17 +00:00
|
|
|
|
newH = height;
|
|
|
|
|
newW = Math.round(newH * srcAspectRatio);
|
2019-05-13 16:01:50 +00:00
|
|
|
|
}
|
2019-05-14 14:04:17 +00:00
|
|
|
|
|
|
|
|
|
return {width: newW, height: newH};
|
2019-02-11 21:55:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 11:26:28 +00:00
|
|
|
|
thumbnailSizes() {
|
2018-09-24 17:07:43 +00:00
|
|
|
|
const result = [];
|
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
|
result.push("(min-width: 2560px) 3840px");
|
|
|
|
|
result.push("(min-width: 1920px) 2560px");
|
|
|
|
|
result.push("(min-width: 1280px) 1920px");
|
|
|
|
|
result.push("(min-width: 720px) 1280px");
|
2019-05-13 16:01:50 +00:00
|
|
|
|
result.push("720px");
|
2018-09-24 17:07:43 +00:00
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
|
return result.join(", ");
|
2018-09-24 17:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 22:04:34 +00:00
|
|
|
|
getDateString() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (!this.TakenAt || this.Year === YearUnknown) {
|
2020-05-15 13:29:56 +00:00
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-23 23:45:59 +00:00
|
|
|
|
if (this.TimeZone) {
|
2019-09-19 21:23:39 +00:00
|
|
|
|
return DateTime.fromISO(this.TakenAt).setZone(this.TimeZone).toLocaleString(DateTime.DATETIME_FULL);
|
2020-05-15 13:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DateTime.fromISO(this.TakenAt).setZone("UTC").toLocaleString(DateTime.DATE_HUGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shortDateString() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (!this.TakenAt || this.Year === YearUnknown) {
|
2019-09-19 21:23:39 +00:00
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
2020-05-15 13:29:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.TimeZone) {
|
|
|
|
|
return DateTime.fromISO(this.TakenAt).setZone(this.TimeZone).toLocaleString(DateTime.DATE_MED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DateTime.fromISO(this.TakenAt).setZone("UTC").toLocaleString(DateTime.DATE_MED);
|
2019-06-06 22:04:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-08 02:37:45 +00:00
|
|
|
|
hasLocation() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return this.Lat !== 0 || this.Lng !== 0;
|
2019-05-08 02:37:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 17:10:44 +00:00
|
|
|
|
locationInfo() {
|
2020-05-29 10:56:24 +00:00
|
|
|
|
if (this.PlaceID === "zz" && this.Country !== "zz") {
|
2020-05-28 13:12:18 +00:00
|
|
|
|
const country = countries.find(c => c.Code === this.Country);
|
|
|
|
|
|
|
|
|
|
if(country) {
|
|
|
|
|
return country.Name;
|
|
|
|
|
}
|
2018-09-24 17:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:12:18 +00:00
|
|
|
|
return this.LocLabel ? this.LocLabel : "Unknown";
|
2018-09-24 17:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
addSizeInfo(file, info) {
|
2020-05-16 15:07:44 +00:00
|
|
|
|
if (!file) {
|
2020-05-15 13:29:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (file.Width && file.Height) {
|
|
|
|
|
info.push(file.Width + " × " + file.Height);
|
|
|
|
|
} else if (!file.Primary) {
|
2020-05-16 15:07:44 +00:00
|
|
|
|
let main = this.mainFile();
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (main && main.Width && main.Height) {
|
|
|
|
|
info.push(main.Width + " × " + main.Height);
|
2020-05-16 15:07:44 +00:00
|
|
|
|
}
|
2020-05-15 13:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (file.Size > 102400) {
|
|
|
|
|
const size = Number.parseFloat(file.Size) / 1048576;
|
2020-05-15 13:29:56 +00:00
|
|
|
|
|
|
|
|
|
info.push(size.toFixed(1) + " MB");
|
2020-05-23 18:58:58 +00:00
|
|
|
|
} else if (file.Size) {
|
|
|
|
|
const size = Number.parseFloat(file.Size) / 1024;
|
2020-05-15 13:29:56 +00:00
|
|
|
|
|
|
|
|
|
info.push(size.toFixed(1) + " KB");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 09:57:26 +00:00
|
|
|
|
getVideoInfo() {
|
2020-05-15 13:29:56 +00:00
|
|
|
|
let info = [];
|
2020-05-14 09:57:26 +00:00
|
|
|
|
let file = this.videoFile();
|
|
|
|
|
|
2020-05-15 07:39:32 +00:00
|
|
|
|
if (!file) {
|
2020-05-14 09:57:26 +00:00
|
|
|
|
file = this.mainFile();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 07:39:32 +00:00
|
|
|
|
if (!file) {
|
2020-05-14 09:57:26 +00:00
|
|
|
|
return "Video";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (file.Duration > 0) {
|
|
|
|
|
info.push(Util.duration(file.Duration));
|
2020-05-14 09:57:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
this.addSizeInfo(file, info);
|
2020-05-14 09:57:26 +00:00
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
if (!info) {
|
2020-05-14 10:11:04 +00:00
|
|
|
|
return "Video";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
return info.join(", ");
|
2020-05-14 10:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPhotoInfo() {
|
2020-05-15 13:29:56 +00:00
|
|
|
|
let info = [];
|
2020-05-14 10:11:04 +00:00
|
|
|
|
|
|
|
|
|
if (this.Camera) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
info.push(this.Camera.Make + " " + this.Camera.Model);
|
2020-05-14 10:11:04 +00:00
|
|
|
|
} else if (this.CameraModel && this.CameraMake) {
|
2020-05-15 13:29:56 +00:00
|
|
|
|
info.push(this.CameraMake + " " + this.CameraModel);
|
2020-05-14 10:11:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
let file = this.mainFile();
|
2020-05-14 10:11:04 +00:00
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
this.addSizeInfo(file, info);
|
2020-05-14 10:11:04 +00:00
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
if (!info) {
|
2020-05-14 10:11:04 +00:00
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 13:29:56 +00:00
|
|
|
|
return info.join(", ");
|
2020-05-14 09:57:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
|
getCamera() {
|
2020-04-18 23:13:55 +00:00
|
|
|
|
if (this.Camera) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return this.Camera.Make + " " + this.Camera.Model;
|
2020-01-30 05:17:02 +00:00
|
|
|
|
} else if (this.CameraModel) {
|
2019-05-16 10:24:13 +00:00
|
|
|
|
return this.CameraMake + " " + this.CameraModel;
|
2018-09-24 17:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
|
return "Unknown";
|
2018-09-24 17:07:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-21 15:59:12 +00:00
|
|
|
|
toggleLike() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
this.Favorite = !this.Favorite;
|
2019-05-21 15:59:12 +00:00
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (this.Favorite) {
|
2019-05-09 04:48:10 +00:00
|
|
|
|
return Api.post(this.getEntityResource() + "/like");
|
2018-10-31 02:33:18 +00:00
|
|
|
|
} else {
|
2019-05-09 04:48:10 +00:00
|
|
|
|
return Api.delete(this.getEntityResource() + "/like");
|
2018-10-31 02:33:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 16:19:18 +00:00
|
|
|
|
togglePrivate() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
this.Private = !this.Private;
|
2020-04-24 16:19:18 +00:00
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return Api.put(this.getEntityResource(), {Private: this.Private});
|
2020-04-24 16:19:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
setPrimary(uid) {
|
|
|
|
|
return Api.post(this.getEntityResource() + "/primary/" + uid).then((r) => Promise.resolve(this.setValues(r.data)));
|
2020-04-21 08:23:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-21 15:59:12 +00:00
|
|
|
|
like() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
this.Favorite = true;
|
2019-05-21 15:59:12 +00:00
|
|
|
|
return Api.post(this.getEntityResource() + "/like");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unlike() {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
this.Favorite = false;
|
2019-05-21 15:59:12 +00:00
|
|
|
|
return Api.delete(this.getEntityResource() + "/like");
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-29 14:28:20 +00:00
|
|
|
|
addLabel(name) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return Api.post(this.getEntityResource() + "/label", {Name: name, Priority: 10})
|
2020-04-21 08:23:27 +00:00
|
|
|
|
.then((r) => Promise.resolve(this.setValues(r.data)));
|
2020-01-29 14:28:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 19:20:38 +00:00
|
|
|
|
activateLabel(id) {
|
2020-04-18 23:27:07 +00:00
|
|
|
|
return Api.put(this.getEntityResource() + "/label/" + id, {Uncertainty: 0})
|
2020-04-21 08:23:27 +00:00
|
|
|
|
.then((r) => Promise.resolve(this.setValues(r.data)));
|
2020-04-17 19:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renameLabel(id, name) {
|
2020-05-23 18:58:58 +00:00
|
|
|
|
return Api.put(this.getEntityResource() + "/label/" + id, {Label: {Name: name}})
|
2020-04-21 08:23:27 +00:00
|
|
|
|
.then((r) => Promise.resolve(this.setValues(r.data)));
|
2020-04-17 19:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-29 14:28:20 +00:00
|
|
|
|
removeLabel(id) {
|
|
|
|
|
return Api.delete(this.getEntityResource() + "/label/" + id)
|
2020-04-21 08:23:27 +00:00
|
|
|
|
.then((r) => Promise.resolve(this.setValues(r.data)));
|
2020-01-29 14:28:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 16:24:24 +00:00
|
|
|
|
update() {
|
|
|
|
|
const values = this.getValues(true);
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (values.Title) {
|
2020-04-18 21:20:54 +00:00
|
|
|
|
values.TitleSrc = SrcManual;
|
2020-02-07 16:24:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (values.Description) {
|
2020-04-18 21:20:54 +00:00
|
|
|
|
values.DescriptionSrc = SrcManual;
|
2020-03-25 13:14:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:12:18 +00:00
|
|
|
|
if (values.Lat || values.Lng || values.Country) {
|
2020-05-26 10:46:22 +00:00
|
|
|
|
values.LocSrc = SrcManual;
|
2020-02-07 16:24:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 23:13:55 +00:00
|
|
|
|
if (values.TakenAt || values.TimeZone) {
|
2020-04-18 21:20:54 +00:00
|
|
|
|
values.TakenSrc = SrcManual;
|
2020-02-07 16:24:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (values.CameraID || values.LensID || values.FocalLength || values.FNumber || values.Iso || values.Exposure) {
|
2020-04-18 21:20:54 +00:00
|
|
|
|
values.CameraSrc = SrcManual;
|
2020-02-07 16:24:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Api.put(this.getEntityResource(), values).then((response) => Promise.resolve(this.setValues(response.data)));
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 18:17:14 +00:00
|
|
|
|
static getCollectionResource() {
|
2019-05-09 04:48:10 +00:00
|
|
|
|
return "photos";
|
2018-08-07 18:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getModelName() {
|
2019-05-09 04:48:10 +00:00
|
|
|
|
return "Photo";
|
2018-08-07 18:17:14 +00:00
|
|
|
|
}
|
2020-04-23 09:00:29 +00:00
|
|
|
|
|
|
|
|
|
static mergeResponse(results, response) {
|
|
|
|
|
if (response.offset === 0 || results.length === 0) {
|
|
|
|
|
return response.models;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (response.models.length > 0) {
|
|
|
|
|
let i = results.length - 1;
|
|
|
|
|
|
2020-05-23 18:58:58 +00:00
|
|
|
|
if (results[i].UID === response.models[0].UID) {
|
2020-04-23 09:00:29 +00:00
|
|
|
|
const first = response.models.shift();
|
2020-04-23 12:30:28 +00:00
|
|
|
|
results[i].Files = results[i].Files.concat(first.Files);
|
2020-04-23 09:00:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results.concat(response.models);
|
|
|
|
|
}
|
2018-08-07 18:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Photo;
|