feat: 带图评论
This commit is contained in:
@ -592,4 +592,7 @@ class Api {
|
||||
/// 直播间记录
|
||||
static const String liveRoomEntry =
|
||||
'${HttpString.liveBaseUrl}/xlive/web-room/v1/index/roomEntryAction';
|
||||
|
||||
/// 图片上传
|
||||
static const String uploadImage = '/x/dynamic/feed/draw/upload_bfs';
|
||||
}
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../models/video/reply/data.dart';
|
||||
import '../models/video/reply/emote.dart';
|
||||
import 'api.dart';
|
||||
@ -115,4 +118,44 @@ class ReplyHttp {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 图片上传
|
||||
static Future uploadImage({required XFile xFile, String type = 'im'}) async {
|
||||
var formData = FormData.fromMap({
|
||||
'file_up': await xFileToMultipartFile(xFile),
|
||||
'biz': type,
|
||||
'csrf': await Request.getCsrf(),
|
||||
'build': 0,
|
||||
'mobi_app': 'web',
|
||||
});
|
||||
var res = await Request().post(
|
||||
Api.uploadImage,
|
||||
data: formData,
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
var data = res.data['data'];
|
||||
data['img_src'] = data['image_url'];
|
||||
data['img_width'] = data['image_width'];
|
||||
data['img_height'] = data['image_height'];
|
||||
data.remove('image_url');
|
||||
data.remove('image_width');
|
||||
data.remove('image_height');
|
||||
return {
|
||||
'status': true,
|
||||
'data': data,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'date': [],
|
||||
'msg': res.data['message'],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static Future<MultipartFile> xFileToMultipartFile(XFile xFile) async {
|
||||
var file = File(xFile.path);
|
||||
var bytes = await file.readAsBytes();
|
||||
return MultipartFile.fromBytes(bytes, filename: xFile.name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import '../common/constants.dart';
|
||||
import '../models/common/reply_type.dart';
|
||||
@ -343,18 +345,35 @@ class VideoHttp {
|
||||
required String message,
|
||||
int? root,
|
||||
int? parent,
|
||||
List<Map<dynamic, dynamic>>? pictures,
|
||||
}) async {
|
||||
if (message == '') {
|
||||
return {'status': false, 'data': [], 'msg': '请输入评论内容'};
|
||||
}
|
||||
var res = await Request().post(Api.replyAdd, queryParameters: {
|
||||
'type': type.index,
|
||||
var params = <String, dynamic>{
|
||||
'plat': 1,
|
||||
'oid': oid,
|
||||
'root': root == null || root == 0 ? '' : root,
|
||||
'parent': parent == null || parent == 0 ? '' : parent,
|
||||
'type': type.index,
|
||||
// 'root': root == null || root == 0 ? '' : root,
|
||||
// 'parent': parent == null || parent == 0 ? '' : parent,
|
||||
'message': message,
|
||||
'at_name_to_mid': {},
|
||||
if (pictures != null) 'pictures': jsonEncode(pictures),
|
||||
'gaia_source': 'main_web',
|
||||
'csrf': await Request.getCsrf(),
|
||||
});
|
||||
};
|
||||
Map sign = await WbiSign().makSign(params);
|
||||
params.remove('wts');
|
||||
params.remove('w_rid');
|
||||
FormData formData = FormData.fromMap({...params});
|
||||
var res = await Request().post(
|
||||
Api.replyAdd,
|
||||
queryParameters: {
|
||||
'w_rid': sign['w_rid'],
|
||||
'wts': sign['wts'],
|
||||
},
|
||||
data: formData,
|
||||
);
|
||||
log(res.toString());
|
||||
if (res.data['code'] == 0) {
|
||||
return {'status': true, 'data': res.data['data']};
|
||||
|
||||
Reference in New Issue
Block a user