2019-05-09 04:48:10 +00:00
|
|
|
import Abstract from "model/abstract";
|
|
|
|
import Api from "common/api";
|
2020-01-23 23:45:59 +00:00
|
|
|
import {DateTime} from "luxon";
|
2018-08-07 18:17:14 +00:00
|
|
|
|
|
|
|
class Photo extends Abstract {
|
2020-01-23 23:45:59 +00:00
|
|
|
getDefaults() {
|
|
|
|
return {
|
|
|
|
ID: 0,
|
|
|
|
TakenAt: "",
|
|
|
|
PhotoUUID: "",
|
|
|
|
PhotoPath: "",
|
|
|
|
PhotoName: "",
|
|
|
|
PhotoTitle: "",
|
|
|
|
PhotoFavorite: false,
|
|
|
|
PhotoPrivate: false,
|
|
|
|
PhotoNSFW: false,
|
|
|
|
PhotoStory: false,
|
|
|
|
PhotoLat: 0.0,
|
|
|
|
PhotoLng: 0.0,
|
|
|
|
PhotoAltitude: 0,
|
|
|
|
PhotoFocalLength: 0,
|
|
|
|
PhotoIso: 0,
|
2020-01-24 09:25:08 +00:00
|
|
|
PhotoFNumber: 0.0,
|
2020-01-23 23:45:59 +00:00
|
|
|
PhotoExposure: "",
|
|
|
|
PhotoViews: 0,
|
|
|
|
Camera: {},
|
|
|
|
CameraID: 0,
|
|
|
|
Lens: {},
|
|
|
|
LensID: 0,
|
|
|
|
CountryChanged: false,
|
|
|
|
Location: null,
|
|
|
|
LocationID: "",
|
|
|
|
Place: null,
|
|
|
|
PlaceID: "",
|
|
|
|
LocationEstimated: false,
|
|
|
|
PhotoCountry: "",
|
|
|
|
PhotoYear: 0,
|
|
|
|
PhotoMonth: 0,
|
|
|
|
TakenAtLocal: "",
|
2020-02-07 16:24:24 +00:00
|
|
|
ModifiedTitle: false,
|
2020-03-26 08:41:33 +00:00
|
|
|
ModifiedDescription: false,
|
|
|
|
ModifiedDate: false,
|
2020-02-07 16:24:24 +00:00
|
|
|
ModifiedLocation: false,
|
2020-03-26 08:41:33 +00:00
|
|
|
ModifiedCamera: false,
|
2020-01-23 23:45:59 +00:00
|
|
|
TimeZone: "",
|
2020-03-26 08:41:33 +00:00
|
|
|
Description: {
|
|
|
|
PhotoDescription: "",
|
|
|
|
PhotoKeywords: "",
|
|
|
|
PhotoNotes: "",
|
|
|
|
PhotoSubject: "",
|
|
|
|
PhotoArtist: "",
|
|
|
|
PhotoCopyright: "",
|
|
|
|
PhotoLicense: "",
|
|
|
|
},
|
2020-01-23 23:45:59 +00:00
|
|
|
Files: [],
|
|
|
|
Labels: [],
|
|
|
|
Keywords: [],
|
|
|
|
Albums: [],
|
|
|
|
CreatedAt: "",
|
|
|
|
UpdatedAt: "",
|
|
|
|
DeletedAt: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-07 18:17:14 +00:00
|
|
|
getEntityName() {
|
2018-09-12 14:37:30 +00:00
|
|
|
return this.PhotoTitle;
|
2018-08-07 18:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getId() {
|
2019-12-04 14:14:04 +00:00
|
|
|
return this.PhotoUUID;
|
2018-08-07 18:17:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 02:37:45 +00:00
|
|
|
getTitle() {
|
|
|
|
return this.PhotoTitle;
|
|
|
|
}
|
|
|
|
|
2019-04-26 00:22:53 +00:00
|
|
|
getColor() {
|
|
|
|
switch (this.PhotoColor) {
|
2020-01-31 14:29:06 +00:00
|
|
|
case "brown":
|
|
|
|
case "black":
|
|
|
|
case "white":
|
|
|
|
case "grey":
|
|
|
|
return "grey lighten-2";
|
|
|
|
default:
|
|
|
|
return this.PhotoColor + " lighten-4";
|
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() {
|
2019-12-20 19:23:16 +00:00
|
|
|
return "https://www.google.com/maps/place/" + this.PhotoLat + "," + this.PhotoLng;
|
2018-08-09 21:10:05 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 00:33:04 +00:00
|
|
|
refreshFileAttr() {
|
|
|
|
if(!this.Files) {
|
2020-01-31 14:29:06 +00:00
|
|
|
return;
|
2020-01-24 00:33:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const primary = this.Files.find(f => f.FilePrimary === true);
|
|
|
|
|
|
|
|
if(!primary) {
|
2020-01-31 14:29:06 +00:00
|
|
|
return;
|
2020-01-24 00:33:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.FileHash = primary.FileHash;
|
|
|
|
this.FileWidth = primary.FileWidth;
|
|
|
|
this.FileHeight = primary.FileHeight;
|
2018-09-24 09:27:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 00:33:04 +00:00
|
|
|
getThumbnailUrl(type) {
|
|
|
|
if(this.FileHash) {
|
|
|
|
return "/api/v1/thumbnails/" + this.FileHash + "/" + type;
|
2020-01-23 23:45:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 00:33:04 +00:00
|
|
|
return "/api/v1/svg/photo";
|
2020-01-23 23:45:59 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 16:16:35 +00:00
|
|
|
getDownloadUrl() {
|
|
|
|
return "/api/v1/download/" + this.FileHash;
|
|
|
|
}
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
getThumbnailSrcset() {
|
|
|
|
const result = [];
|
|
|
|
|
2020-01-23 23:45:59 +00:00
|
|
|
result.push(this.getThumbnailUrl("fit_720") + " 720w");
|
2019-05-13 16:01:50 +00:00
|
|
|
result.push(this.getThumbnailUrl("fit_1280") + " 1280w");
|
|
|
|
result.push(this.getThumbnailUrl("fit_1920") + " 1920w");
|
|
|
|
result.push(this.getThumbnailUrl("fit_2560") + " 2560w");
|
|
|
|
result.push(this.getThumbnailUrl("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-01-23 23:45:59 +00:00
|
|
|
if (width >= this.FileWidth && height >= this.FileHeight) { // Smaller
|
2019-05-14 14:04:17 +00:00
|
|
|
return {width: this.FileWidth, height: this.FileHeight};
|
2019-05-13 16:01:50 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:04:17 +00:00
|
|
|
const srcAspectRatio = this.FileWidth / this.FileHeight;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
getThumbnailSizes() {
|
|
|
|
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-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-01-23 23:45:59 +00:00
|
|
|
} else if (this.TakenAt) {
|
2019-09-19 21:23:39 +00:00
|
|
|
return DateTime.fromISO(this.TakenAt).toLocaleString(DateTime.DATE_HUGE);
|
|
|
|
} else {
|
|
|
|
return "Unknown";
|
|
|
|
}
|
2019-06-06 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 02:37:45 +00:00
|
|
|
hasLocation() {
|
2019-12-20 19:23:16 +00:00
|
|
|
return this.PhotoLat !== 0 || this.PhotoLng !== 0;
|
2019-05-08 02:37:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
getLocation() {
|
2019-12-28 19:24:20 +00:00
|
|
|
if (this.LocLabel) {
|
|
|
|
return this.LocLabel;
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-12-21 16:24:29 +00:00
|
|
|
return "Unknown";
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getCamera() {
|
2020-01-30 05:17:02 +00:00
|
|
|
if(this.Camera) {
|
|
|
|
return this.Camera.CameraMake + " " + this.Camera.CameraModel;
|
|
|
|
} 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() {
|
|
|
|
this.PhotoFavorite = !this.PhotoFavorite;
|
|
|
|
|
2020-01-23 23:45:59 +00:00
|
|
|
if (this.PhotoFavorite) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 15:59:12 +00:00
|
|
|
like() {
|
|
|
|
this.PhotoFavorite = true;
|
|
|
|
return Api.post(this.getEntityResource() + "/like");
|
|
|
|
}
|
|
|
|
|
|
|
|
unlike() {
|
|
|
|
this.PhotoFavorite = false;
|
|
|
|
return Api.delete(this.getEntityResource() + "/like");
|
|
|
|
}
|
|
|
|
|
2020-01-29 14:28:20 +00:00
|
|
|
addLabel(name) {
|
|
|
|
return Api.post(this.getEntityResource() + "/label", {LabelName: name})
|
2020-01-30 08:51:23 +00:00
|
|
|
.then((response) => Promise.resolve(this.setValues(response.data)));
|
2020-01-29 14:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
removeLabel(id) {
|
|
|
|
return Api.delete(this.getEntityResource() + "/label/" + id)
|
2020-01-30 08:51:23 +00:00
|
|
|
.then((response) => Promise.resolve(this.setValues(response.data)));
|
2020-01-29 14:28:20 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 16:24:24 +00:00
|
|
|
update() {
|
|
|
|
const values = this.getValues(true);
|
|
|
|
|
|
|
|
if(values.PhotoTitle) {
|
|
|
|
values.ModifiedTitle = true
|
|
|
|
}
|
|
|
|
|
2020-03-26 08:41:33 +00:00
|
|
|
if(values.Description) {
|
|
|
|
values.ModifiedDescription = true
|
2020-03-25 13:14:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 08:41:33 +00:00
|
|
|
if(values.PhotoLat || values.PhotoLng || values.PhotoAltitude || values.PhotoCountry) {
|
2020-02-07 16:24:24 +00:00
|
|
|
values.ModifiedLocation = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if(values.TakenAt || values.TimeZone) {
|
|
|
|
values.ModifiedDate = true
|
|
|
|
}
|
|
|
|
|
2020-03-26 08:41:33 +00:00
|
|
|
if(values.CameraID || values.LensID) {
|
|
|
|
values.ModifiedCamera = true
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Photo;
|