typeFile static method

Future<Map?> typeFile({
  1. required dynamic content,
  2. required Directory? directory_temp,
})

auto set parameters input file

Implementation

static Future<Map?> typeFile({
  required dynamic content,
  required Directory? directory_temp,
}) async {
  if (content is Map) {
    if (content["is_post_buffer"] == true) {
      if (directory_temp != null) {
        final String name_file = () {
          if (content["name"] is String &&
              (content["name"] as String).isNotEmpty) {
            return content["name"];
          }
          return "${DateTime.now().millisecondsSinceEpoch}";
        }();
        final File file = File(join(directory_temp.path, name_file));
        if (content["buffer"] is List<int>) {
          await file.writeAsBytes((content["buffer"] as List<int>));
        }
        return {
          "@type": 'inputFileLocal',
          "path": file.path,
        };
      }
    }
  } else if (content is Uri) {
    return {
      "@type": 'inputFileRemote',
      "id": content.toString(),
    };
  } else if (RegExp(r"^(http)", caseSensitive: false).hashData(content)) {
    return {
      "@type": 'inputFileRemote',
      "id": content,
    };
  } else if (RegExp(r"^(\/|\.\.?\/|~\/)", caseSensitive: false)
      .hashData(content)) {
    return {
      "@type": 'inputFileLocal',
      "path": content,
    };
  } else if (content is File) {
    return {
      "@type": 'inputFileLocal',
      "path": content.path,
    };
  } else if (content is int) {
    return {
      "@type": 'inputFileId',
      "id": content,
    };
  } else {
    return {
      "@type": 'inputFileRemote',
      "id": content,
    };
  }
  return null;
}