livephoto: fix iOS deletion

pull/231/head
Varun Patil 2022-11-22 09:19:31 -08:00
parent d57ab66310
commit 9fe31c87b6
3 changed files with 33 additions and 3 deletions

View File

@ -207,6 +207,11 @@ class VideoController extends ApiBase
$liveFile = $files[0];
if ($liveFile instanceof File) {
// Requested only JSON info
if ('json' === $this->request->getParam('format')) {
return new JSONResponse($lp);
}
$name = $liveFile->getName();
$blob = $liveFile->getContent();
$mime = $liveFile->getMimeType();

View File

@ -1213,7 +1213,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
*/
async deleteFromViewWithAnimation(delPhotos: IPhoto[]) {
// Only keep photos with day
delPhotos = delPhotos.filter((p) => p.d);
delPhotos = delPhotos.filter((p) => p?.d);
if (delPhotos.length === 0) return;
// Get all days that need to be updatd

View File

@ -1,10 +1,13 @@
import { getCurrentUser } from "@nextcloud/auth";
import { showError } from "@nextcloud/dialogs";
import { translate as t } from "@nextcloud/l10n";
import axios from "@nextcloud/axios";
import { IFileInfo, IPhoto } from "../../types";
import client from "../DavClient";
import { genFileInfo } from "../FileUtils";
import { getAlbumFileInfos } from "./albums";
import * as utils from "../Utils";
import client from "../DavClient";
export const props = `
<oc:fileid />
@ -195,10 +198,32 @@ export async function* deletePhotos(photos: IPhoto[]) {
const fileIdsSet = new Set(photos.map((p) => p.fileid));
// Get live photo data
const livePhotos = (
await Promise.all(
photos
.filter((p) => p.liveid && !p.liveid.startsWith("self__"))
.map(async (p) => {
const url = utils.getLivePhotoVideoUrl(p) + "&format=json";
try {
const response = await axios.get(url);
const data = response.data;
fileIdsSet.add(data.fileid);
return {
fileid: data.fileid,
} as IPhoto;
} catch (error) {
console.error(error);
return null;
}
})
)
).filter((p) => p !== null) as IPhoto[];
// Get files data
let fileInfos: IFileInfo[] = [];
try {
fileInfos = await getFiles(photos);
fileInfos = await getFiles(photos.concat(livePhotos));
} catch (e) {
console.error("Failed to get file info for files to delete", photos, e);
showError(t("memories", "Failed to delete files."));