2021-08-05 07:48:32 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
2022-10-15 16:29:18 +02:00
|
|
|
import 'package:nc_photos/entity/file_descriptor.dart';
|
2021-08-05 07:48:32 +02:00
|
|
|
import 'package:nc_photos/exception.dart';
|
2023-02-23 15:49:17 +01:00
|
|
|
import 'package:nc_photos/np_api_util.dart';
|
2022-12-16 16:01:04 +01:00
|
|
|
import 'package:np_codegen/np_codegen.dart';
|
2023-02-23 15:49:17 +01:00
|
|
|
import 'package:np_common/type.dart';
|
2021-08-05 07:48:32 +02:00
|
|
|
|
2022-12-16 16:01:04 +01:00
|
|
|
part 'request_public_link.g.dart';
|
|
|
|
|
|
|
|
@npLog
|
2021-08-05 07:48:32 +02:00
|
|
|
class RequestPublicLink {
|
|
|
|
/// Request a temporary unique public link to [file]
|
2022-10-15 16:29:18 +02:00
|
|
|
Future<String> call(Account account, FileDescriptor file) async {
|
2023-02-23 15:49:17 +01:00
|
|
|
final response = await ApiUtil.fromAccount(account)
|
|
|
|
.ocs()
|
|
|
|
.dav()
|
|
|
|
.direct()
|
|
|
|
.post(fileId: file.fdId);
|
2021-08-05 07:48:32 +02:00
|
|
|
if (!response.isGood) {
|
|
|
|
_log.severe("[call] Failed requesting server: $response");
|
|
|
|
throw ApiException(
|
|
|
|
response: response,
|
2022-07-21 07:45:49 +02:00
|
|
|
message:
|
|
|
|
"Server responed with an error: HTTP ${response.statusCode}");
|
2021-08-05 07:48:32 +02:00
|
|
|
}
|
2021-08-06 19:11:00 +02:00
|
|
|
final JsonObj json = jsonDecode(response.body)["ocs"];
|
2021-08-05 07:48:32 +02:00
|
|
|
if (json["meta"]["statuscode"] != 200) {
|
|
|
|
_log.shout(
|
|
|
|
"[call] Failed requesting server: ${jsonEncode(json["meta"])}");
|
|
|
|
throw ApiException(
|
|
|
|
response: response,
|
|
|
|
message:
|
2022-07-21 07:45:49 +02:00
|
|
|
"Server responed with an error: HTTP ${json["meta"]["statuscode"]} ${json["meta"]["message"]}");
|
2021-08-05 07:48:32 +02:00
|
|
|
}
|
|
|
|
return json["data"]["url"];
|
|
|
|
}
|
|
|
|
}
|