mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Fix shared image in collaborative album not showing in viewer
This commit is contained in:
parent
4d9644ac18
commit
067b6a1a60
8 changed files with 25 additions and 45 deletions
|
@ -7,7 +7,6 @@ import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||||
import 'package:nc_photos/entity/nc_album_item.dart';
|
|
||||||
import 'package:nc_photos/exception.dart';
|
import 'package:nc_photos/exception.dart';
|
||||||
import 'package:np_api/np_api.dart' hide NcAlbumItem;
|
import 'package:np_api/np_api.dart' hide NcAlbumItem;
|
||||||
import 'package:to_string/to_string.dart';
|
import 'package:to_string/to_string.dart';
|
||||||
|
@ -46,6 +45,11 @@ String getFilePreviewUrlRelative(
|
||||||
if (file_util.isTrash(account, file)) {
|
if (file_util.isTrash(account, file)) {
|
||||||
// trashbin does not support preview.png endpoint
|
// trashbin does not support preview.png endpoint
|
||||||
url = "index.php/apps/files_trashbin/preview?fileId=${file.fdId}";
|
url = "index.php/apps/files_trashbin/preview?fileId=${file.fdId}";
|
||||||
|
} else if (file_util.isNcAlbumFile(account, file)) {
|
||||||
|
// We can't use the generic file preview url because collaborative albums do
|
||||||
|
// not create a file share for photos not belonging to you, that means you
|
||||||
|
// can only access the file view the Photos API
|
||||||
|
url = "apps/photos/api/v1/preview/${file.fdId}?x=$width&y=$height";
|
||||||
} else {
|
} else {
|
||||||
url = "index.php/core/preview?fileId=${file.fdId}";
|
url = "index.php/core/preview?fileId=${file.fdId}";
|
||||||
}
|
}
|
||||||
|
@ -77,18 +81,6 @@ String getFilePreviewUrlByFileId(
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the preview image URL for an item in [NcAlbum]. We can't use the
|
|
||||||
/// generic file preview url because collaborative albums do not create a file
|
|
||||||
/// share for photos not belonging to you, that means you can only access the
|
|
||||||
/// file view the Photos API
|
|
||||||
String getNcAlbumFilePreviewUrl(
|
|
||||||
Account account,
|
|
||||||
NcAlbumItem item, {
|
|
||||||
required int width,
|
|
||||||
required int height,
|
|
||||||
}) =>
|
|
||||||
"${account.url}/apps/photos/api/v1/preview/${item.fileId}?x=$width&y=$height";
|
|
||||||
|
|
||||||
String getFileUrl(Account account, FileDescriptor file) {
|
String getFileUrl(Account account, FileDescriptor file) {
|
||||||
return "${account.url}/${getFileUrlRelative(file)}";
|
return "${account.url}/${getFileUrlRelative(file)}";
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||||
import 'package:nc_photos/platform/k.dart' as platform_k;
|
import 'package:nc_photos/platform/k.dart' as platform_k;
|
||||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||||
|
import 'package:np_api/np_api.dart' as api;
|
||||||
import 'package:np_common/ci_string.dart';
|
import 'package:np_common/ci_string.dart';
|
||||||
import 'package:np_common/string_extension.dart';
|
import 'package:np_common/string_extension.dart';
|
||||||
import 'package:path/path.dart' as path_lib;
|
import 'package:path/path.dart' as path_lib;
|
||||||
|
@ -38,6 +39,9 @@ bool isTrash(Account account, FileDescriptor file) =>
|
||||||
bool isAlbumFile(Account account, FileDescriptor file) =>
|
bool isAlbumFile(Account account, FileDescriptor file) =>
|
||||||
file.fdPath.startsWith(remote_storage_util.getRemoteAlbumsDir(account));
|
file.fdPath.startsWith(remote_storage_util.getRemoteAlbumsDir(account));
|
||||||
|
|
||||||
|
bool isNcAlbumFile(Account account, FileDescriptor file) =>
|
||||||
|
file.fdPath.startsWith("${api.ApiPhotos.path}/");
|
||||||
|
|
||||||
/// Return if [file] is located under [dir]
|
/// Return if [file] is located under [dir]
|
||||||
///
|
///
|
||||||
/// Return false if [file] is [dir] itself (since it's not "under")
|
/// Return false if [file] is [dir] itself (since it's not "under")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:copy_with/copy_with.dart';
|
import 'package:copy_with/copy_with.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
|
import 'package:np_api/np_api.dart' as api;
|
||||||
import 'package:np_common/ci_string.dart';
|
import 'package:np_common/ci_string.dart';
|
||||||
import 'package:np_common/string_extension.dart';
|
import 'package:np_common/string_extension.dart';
|
||||||
import 'package:np_common/type.dart';
|
import 'package:np_common/type.dart';
|
||||||
|
@ -27,7 +28,7 @@ class NcAlbum with EquatableMixin {
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
return NcAlbum(
|
return NcAlbum(
|
||||||
path: "remote.php/dav/photos/${account.userId}/albums/$name",
|
path: "${api.ApiPhotos.path}/${account.userId}/albums/$name",
|
||||||
lastPhoto: null,
|
lastPhoto: null,
|
||||||
nbItems: 0,
|
nbItems: 0,
|
||||||
location: null,
|
location: null,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
|
import 'package:np_api/np_api.dart' as api;
|
||||||
import 'package:np_common/string_extension.dart';
|
import 'package:np_common/string_extension.dart';
|
||||||
import 'package:to_string/to_string.dart';
|
import 'package:to_string/to_string.dart';
|
||||||
|
|
||||||
|
@ -40,10 +41,10 @@ extension NcAlbumItemExtension on NcAlbumItem {
|
||||||
/// WebDAV file path: remote.php/dav/photos/{userId}/albums/{album}/{strippedPath}.
|
/// WebDAV file path: remote.php/dav/photos/{userId}/albums/{album}/{strippedPath}.
|
||||||
/// If this path points to the user's root album path, return "."
|
/// If this path points to the user's root album path, return "."
|
||||||
String get strippedPath {
|
String get strippedPath {
|
||||||
if (!path.startsWith("remote.php/dav/photos/")) {
|
if (!path.startsWith("${api.ApiPhotos.path}/")) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
var begin = "remote.php/dav/photos/".length;
|
var begin = "${api.ApiPhotos.path}/".length;
|
||||||
begin = path.indexOf("/", begin);
|
begin = path.indexOf("/", begin);
|
||||||
if (begin == -1) {
|
if (begin == -1) {
|
||||||
return path;
|
return path;
|
||||||
|
|
|
@ -16,6 +16,7 @@ import 'package:nc_photos/entity/tag.dart';
|
||||||
import 'package:nc_photos/iterable_extension.dart';
|
import 'package:nc_photos/iterable_extension.dart';
|
||||||
import 'package:nc_photos/object_extension.dart';
|
import 'package:nc_photos/object_extension.dart';
|
||||||
import 'package:nc_photos/or_null.dart';
|
import 'package:nc_photos/or_null.dart';
|
||||||
|
import 'package:np_api/np_api.dart' as api;
|
||||||
import 'package:np_common/ci_string.dart';
|
import 'package:np_common/ci_string.dart';
|
||||||
|
|
||||||
extension SqlTagListExtension on List<sql.Tag> {
|
extension SqlTagListExtension on List<sql.Tag> {
|
||||||
|
@ -259,7 +260,7 @@ class SqliteNcAlbumConverter {
|
||||||
final json = ncAlbum.collaborators
|
final json = ncAlbum.collaborators
|
||||||
.run((obj) => (jsonDecode(obj) as List).cast<Map>());
|
.run((obj) => (jsonDecode(obj) as List).cast<Map>());
|
||||||
return NcAlbum(
|
return NcAlbum(
|
||||||
path: "remote.php/dav/photos/$userId/albums/${ncAlbum.relativePath}",
|
path: "${api.ApiPhotos.path}/$userId/albums/${ncAlbum.relativePath}",
|
||||||
lastPhoto: ncAlbum.lastPhoto,
|
lastPhoto: ncAlbum.lastPhoto,
|
||||||
nbItems: ncAlbum.nbItems,
|
nbItems: ncAlbum.nbItems,
|
||||||
location: ncAlbum.location,
|
location: ncAlbum.location,
|
||||||
|
@ -291,7 +292,7 @@ class SqliteNcAlbumItemConverter {
|
||||||
String userId, String albumRelativePath, sql.NcAlbumItem item) =>
|
String userId, String albumRelativePath, sql.NcAlbumItem item) =>
|
||||||
NcAlbumItem(
|
NcAlbumItem(
|
||||||
path:
|
path:
|
||||||
"remote.php/dav/photos/$userId/albums/$albumRelativePath/${item.relativePath}",
|
"${api.ApiPhotos.path}/$userId/albums/$albumRelativePath/${item.relativePath}",
|
||||||
fileId: item.fileId,
|
fileId: item.fileId,
|
||||||
contentLength: item.contentLength,
|
contentLength: item.contentLength,
|
||||||
contentType: item.contentType,
|
contentType: item.contentType,
|
||||||
|
|
|
@ -47,8 +47,7 @@ class _PhotoItem extends _FileItem {
|
||||||
required super.original,
|
required super.original,
|
||||||
required super.file,
|
required super.file,
|
||||||
required this.account,
|
required this.account,
|
||||||
}) : _previewUrl = _getCollectionFilePreviewUrl(
|
}) : _previewUrl = NetworkRectThumbnail.imageUrlForFile(account, file);
|
||||||
account, original as CollectionFileItem);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
StaggeredTile get staggeredTile => const StaggeredTile.count(1, 1);
|
StaggeredTile get staggeredTile => const StaggeredTile.count(1, 1);
|
||||||
|
@ -76,8 +75,7 @@ class _VideoItem extends _FileItem {
|
||||||
required super.original,
|
required super.original,
|
||||||
required super.file,
|
required super.file,
|
||||||
required this.account,
|
required this.account,
|
||||||
}) : _previewUrl = _getCollectionFilePreviewUrl(
|
}) : _previewUrl = NetworkRectThumbnail.imageUrlForFile(account, file);
|
||||||
account, original as CollectionFileItem);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
StaggeredTile get staggeredTile => const StaggeredTile.count(1, 1);
|
StaggeredTile get staggeredTile => const StaggeredTile.count(1, 1);
|
||||||
|
@ -176,13 +174,3 @@ class _DateItem extends _Item {
|
||||||
|
|
||||||
final DateTime date;
|
final DateTime date;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getCollectionFilePreviewUrl(Account account, CollectionFileItem item) {
|
|
||||||
if (item is CollectionFileItemNcAlbumItemAdapter) {
|
|
||||||
return item.localFile == null
|
|
||||||
? NetworkRectThumbnail.imageUrlForNcAlbumFile(account, item.item)
|
|
||||||
: NetworkRectThumbnail.imageUrlForFile(account, item.file);
|
|
||||||
} else {
|
|
||||||
return NetworkRectThumbnail.imageUrlForFile(account, item.file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||||
import 'package:nc_photos/cache_manager_util.dart';
|
import 'package:nc_photos/cache_manager_util.dart';
|
||||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||||
import 'package:nc_photos/entity/nc_album_item.dart';
|
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
import 'package:nc_photos/np_api_util.dart';
|
import 'package:nc_photos/np_api_util.dart';
|
||||||
|
|
||||||
|
@ -37,14 +36,6 @@ class NetworkRectThumbnail extends StatelessWidget {
|
||||||
isKeepAspectRatio: true,
|
isKeepAspectRatio: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
static String imageUrlForNcAlbumFile(Account account, NcAlbumItem item) =>
|
|
||||||
api_util.getNcAlbumFilePreviewUrl(
|
|
||||||
account,
|
|
||||||
item,
|
|
||||||
width: k.photoThumbSize,
|
|
||||||
height: k.photoThumbSize,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final child = FittedBox(
|
final child = FittedBox(
|
||||||
|
|
|
@ -6,6 +6,8 @@ class ApiPhotos {
|
||||||
ApiPhotosAlbums albums() => ApiPhotosAlbums(this);
|
ApiPhotosAlbums albums() => ApiPhotosAlbums(this);
|
||||||
ApiPhotosAlbum album(String name) => ApiPhotosAlbum(this, name);
|
ApiPhotosAlbum album(String name) => ApiPhotosAlbum(this, name);
|
||||||
|
|
||||||
|
static String get path => "remote.php/dav/photos";
|
||||||
|
|
||||||
final Api api;
|
final Api api;
|
||||||
final String userId;
|
final String userId;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +24,7 @@ class ApiPhotosAlbums {
|
||||||
dateRange,
|
dateRange,
|
||||||
collaborators,
|
collaborators,
|
||||||
}) async {
|
}) async {
|
||||||
final endpoint = "remote.php/dav/photos/${photos.userId}/albums";
|
final endpoint = "${ApiPhotos.path}/${photos.userId}/albums";
|
||||||
try {
|
try {
|
||||||
if (lastPhoto == null &&
|
if (lastPhoto == null &&
|
||||||
nbItems == null &&
|
nbItems == null &&
|
||||||
|
@ -96,7 +98,7 @@ class ApiPhotosAlbum {
|
||||||
fileid,
|
fileid,
|
||||||
permissions,
|
permissions,
|
||||||
}) async {
|
}) async {
|
||||||
final endpoint = "remote.php/dav/photos/${photos.userId}/albums/$albumId";
|
final endpoint = "${ApiPhotos.path}/${photos.userId}/albums/$albumId";
|
||||||
try {
|
try {
|
||||||
final bool hasDavNs = (getcontentlength != null ||
|
final bool hasDavNs = (getcontentlength != null ||
|
||||||
getcontenttype != null ||
|
getcontenttype != null ||
|
||||||
|
@ -178,7 +180,7 @@ class ApiPhotosAlbum {
|
||||||
|
|
||||||
Future<Response> mkcol() async {
|
Future<Response> mkcol() async {
|
||||||
try {
|
try {
|
||||||
final endpoint = "remote.php/dav/photos/${photos.userId}/albums/$albumId";
|
final endpoint = "${ApiPhotos.path}/${photos.userId}/albums/$albumId";
|
||||||
return await api.request("MKCOL", endpoint);
|
return await api.request("MKCOL", endpoint);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_log.severe("[mkcol] Failed while MKCOL", e);
|
_log.severe("[mkcol] Failed while MKCOL", e);
|
||||||
|
@ -188,7 +190,7 @@ class ApiPhotosAlbum {
|
||||||
|
|
||||||
Future<Response> delete() async {
|
Future<Response> delete() async {
|
||||||
try {
|
try {
|
||||||
final endpoint = "remote.php/dav/photos/${photos.userId}/albums/$albumId";
|
final endpoint = "${ApiPhotos.path}/${photos.userId}/albums/$albumId";
|
||||||
return await api.request("DELETE", endpoint);
|
return await api.request("DELETE", endpoint);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_log.severe("[delete] Failed while DELETE", e);
|
_log.severe("[delete] Failed while DELETE", e);
|
||||||
|
|
Loading…
Reference in a new issue