mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Can post PDFs
This commit is contained in:
@ -56,8 +56,11 @@ class APIHelper {
|
||||
var v = request.bytesFiles[key];
|
||||
data.files.add(MapEntry(
|
||||
key,
|
||||
MultipartFile.fromBytes(v.bytes,
|
||||
filename: v.filename.split("/").last)));
|
||||
MultipartFile.fromBytes(
|
||||
v.bytes,
|
||||
filename: v.filename.split("/").last,
|
||||
contentType: v.type,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/displayed_content.dart';
|
||||
import 'package:comunic/models/new_post.dart';
|
||||
import 'package:comunic/models/post.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
/// Posts helper
|
||||
///
|
||||
@ -57,7 +58,7 @@ class PostsHelper {
|
||||
/// failure
|
||||
Future<PostsList> getLatest({int from = 0}) async {
|
||||
final response =
|
||||
await APIRequest(uri: "posts/get_latest", needLogin: true, args: {
|
||||
await APIRequest(uri: "posts/get_latest", needLogin: true, args: {
|
||||
"include_groups": true.toString(),
|
||||
"startFrom": from.toString(),
|
||||
}).exec();
|
||||
@ -76,7 +77,8 @@ class PostsHelper {
|
||||
/// Get the list of posts of a user
|
||||
Future<PostsList> getUserPosts(int userID, {int from = 0}) async {
|
||||
final response = await (APIRequest(uri: "posts/get_user", needLogin: true)
|
||||
..addInt("userID", userID)..addInt("startFrom", from == 0 ? 0 : from - 1))
|
||||
..addInt("userID", userID)
|
||||
..addInt("startFrom", from == 0 ? 0 : from - 1))
|
||||
.exec();
|
||||
|
||||
if (response.code != 200) return null;
|
||||
@ -93,7 +95,8 @@ class PostsHelper {
|
||||
/// Get the list of posts of a group
|
||||
Future<PostsList> getGroupPosts(int groupID, {int from = 0}) async {
|
||||
final response = await (APIRequest(uri: "posts/get_group", needLogin: true)
|
||||
..addInt("groupID", groupID)..addInt("startFrom", from == 0 ? 0 : from - 1))
|
||||
..addInt("groupID", groupID)
|
||||
..addInt("startFrom", from == 0 ? 0 : from - 1))
|
||||
.exec();
|
||||
|
||||
if (response.code != 200) return null;
|
||||
@ -126,11 +129,11 @@ class PostsHelper {
|
||||
/// This function crash in case of error
|
||||
Future<void> createPost(NewPost post) async {
|
||||
APIRequest request =
|
||||
APIRequest(uri: "posts/create", needLogin: true, args: {
|
||||
APIRequest(uri: "posts/create", needLogin: true, args: {
|
||||
"kind-page": _APIPostsTargetKindsMap[post.target],
|
||||
"kind-id": post.targetID.toString(),
|
||||
"visibility": _APIPostsVisibilityLevelMap.map(
|
||||
(s, v) => MapEntry(v, s))[post.visibility],
|
||||
(s, v) => MapEntry(v, s))[post.visibility],
|
||||
"kind": _APIPostsKindsMap.map((s, k) => MapEntry(k, s))[post.kind],
|
||||
"content": post.content
|
||||
});
|
||||
@ -143,6 +146,13 @@ class PostsHelper {
|
||||
request.addFile("image", post.image);
|
||||
break;
|
||||
|
||||
case PostKind.PDF:
|
||||
request.addBytesFile(
|
||||
"pdf",
|
||||
BytesFile("file.pdf", post.pdf,
|
||||
type: MediaType.parse("application/pdf")));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw Exception("Unsupported post type :" + post.kind.toString());
|
||||
break;
|
||||
@ -174,7 +184,7 @@ class PostsHelper {
|
||||
args: {
|
||||
"postID": id.toString(),
|
||||
"new_level":
|
||||
_APIPostsVisibilityLevelMap.map((k, v) => MapEntry(v, k))[level]
|
||||
_APIPostsVisibilityLevelMap.map((k, v) => MapEntry(v, k))[level]
|
||||
},
|
||||
).exec())
|
||||
.isOK;
|
||||
|
Reference in New Issue
Block a user