slack file upload update
This commit is contained in:
parent
cfb9ba131c
commit
cd2b4a25ad
5 changed files with 19 additions and 29 deletions
|
|
@ -44,20 +44,19 @@ class AppDataManager {
|
|||
var c = Completer<String>();
|
||||
var number = 0;
|
||||
var shell = StringBuffer();
|
||||
switch (this._scm) {
|
||||
switch (_scm) {
|
||||
case SCMType.Svn:
|
||||
break;
|
||||
case SCMType.Git:
|
||||
shell.writeln('git rev-list --all HEAD --all --count');
|
||||
var process =
|
||||
await ProcessExecutor.start(shell, workspace: this._workspace);
|
||||
var process = await ProcessExecutor.start(shell, workspace: _workspace);
|
||||
await process.process.exitCode;
|
||||
number = int.parse(process.stdoutArr.last);
|
||||
break;
|
||||
}
|
||||
|
||||
var version = this.numberToVersion(number);
|
||||
print('#### Version: ' + version);
|
||||
var version = numberToVersion(number);
|
||||
print('#### Version: $version');
|
||||
c.complete(version);
|
||||
return c.future;
|
||||
}
|
||||
|
|
@ -97,7 +96,7 @@ class AppDataManager {
|
|||
await ProcessExecutor.start(shell, workspace: this._workspace);
|
||||
await process.process.exitCode;
|
||||
var hash = process.stdoutArr.last;
|
||||
print('#### Git Hash: ' + hash);
|
||||
print('#### Git Hash: $hash');
|
||||
c.complete(hash);
|
||||
return c.future;
|
||||
}
|
||||
|
|
@ -105,7 +104,7 @@ class AppDataManager {
|
|||
String getBuildTime() {
|
||||
var date = DateTime.now().toString();
|
||||
date = date.substring(0, date.lastIndexOf('.'));
|
||||
print('#### Build Date: ' + date);
|
||||
print('#### Build Date: $date');
|
||||
return date;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ class Log {
|
|||
if (message.type == 'request') {
|
||||
write();
|
||||
} else if (message.type == 'ready') {
|
||||
path = message.message as String;
|
||||
appendString('Log path: ${message.message}');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,14 +182,13 @@ class SlackConfirm {
|
|||
}
|
||||
|
||||
// To-do: File upload test
|
||||
@JsonSerializable()
|
||||
class SlackFile {
|
||||
String? title;
|
||||
// ignore: non_constant_identifier_names
|
||||
String? initial_comment;
|
||||
String? filePath;
|
||||
String? fileName;
|
||||
String? mimeType;
|
||||
late File file;
|
||||
|
||||
Future<MultipartRequest> setFileData(MultipartRequest form) async {
|
||||
// var bytes = await readFileByte(filePath!);
|
||||
|
|
@ -202,8 +201,7 @@ class SlackFile {
|
|||
form.fields['filetype'] =
|
||||
"auto"; //참조 - https://api.slack.com/types/file#file_types
|
||||
if (fileName != null && mimeType != null) {
|
||||
form.files.add(MultipartFile.fromBytes(
|
||||
'file', await File.fromUri(Uri.parse(filePath!)).readAsBytes(),
|
||||
form.files.add(await MultipartFile.fromPath('file', file.path,
|
||||
contentType: MediaType(HttpHeaders.contentTypeHeader, mimeType!)));
|
||||
}
|
||||
var c = Completer<MultipartRequest>();
|
||||
|
|
|
|||
|
|
@ -182,18 +182,3 @@ Map<String, dynamic> _$SlackConfirmToJson(SlackConfirm instance) =>
|
|||
'ok_text': instance.ok_text,
|
||||
'dismiss_text': instance.dismiss_text,
|
||||
};
|
||||
|
||||
SlackFile _$SlackFileFromJson(Map<String, dynamic> json) => SlackFile()
|
||||
..title = json['title'] as String?
|
||||
..initial_comment = json['initial_comment'] as String?
|
||||
..filePath = json['filePath'] as String?
|
||||
..fileName = json['fileName'] as String?
|
||||
..mimeType = json['mimeType'] as String?;
|
||||
|
||||
Map<String, dynamic> _$SlackFileToJson(SlackFile instance) => <String, dynamic>{
|
||||
'title': instance.title,
|
||||
'initial_comment': instance.initial_comment,
|
||||
'filePath': instance.filePath,
|
||||
'fileName': instance.fileName,
|
||||
'mimeType': instance.mimeType,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -109,15 +109,22 @@ class SlackSender {
|
|||
return form;
|
||||
}
|
||||
|
||||
void sendFile(String channel, SlackFile file,
|
||||
Future sendFile(String channel, SlackFile file,
|
||||
{String? targetUser,
|
||||
Function(String)? completeListener,
|
||||
Function(Exception)? errorListener}) async {
|
||||
var c = Completer();
|
||||
_completeListener = completeListener;
|
||||
_errorListener = errorListener;
|
||||
var form = getPostForm(urlFileUplaod, channel, targetUser);
|
||||
form = await file.setFileData(form);
|
||||
//To-do: send http
|
||||
var response = await form.send();
|
||||
|
||||
var result = await response.stream.bytesToString();
|
||||
if (_completeListener != null) _completeListener!(result);
|
||||
|
||||
c.complete();
|
||||
return c.future;
|
||||
}
|
||||
|
||||
/// ****************** Send template *******************
|
||||
|
|
@ -143,7 +150,7 @@ class SlackSender {
|
|||
SlackField.withParam('Test4', 'Value4'),
|
||||
];
|
||||
message.attachments.add(attachment);
|
||||
sends('app_notifier', message, targetUser: 'toki');
|
||||
await sends('app_notifier', message, targetUser: 'toki');
|
||||
}
|
||||
|
||||
Future sendBuild(String appName, SlackBuildType buildType, Color color,
|
||||
|
|
|
|||
Loading…
Reference in a new issue