@@ -9,7 +9,6 @@ use anyhow::{Context as AnyhowContext, Result, anyhow};
99use chrono:: DateTime ;
1010use crossterm:: style:: Stylize ;
1111use pbjson_types:: Timestamp ;
12- use reqwest:: header:: { CONTENT_ENCODING , CONTENT_TYPE } ;
1312use sift_rs:: {
1413 common:: r#type:: v1:: { ChannelConfig , ChannelDataType } ,
1514 data_imports:: v2:: {
@@ -25,15 +24,12 @@ use crate::{
2524 Context ,
2625 import:: utils:: { try_parse_bit_field_config, try_parse_enum_config} ,
2726 } ,
28- util:: {
29- api:: { create_grpc_channel, create_rest_client} ,
30- tty:: Output ,
31- } ,
27+ util:: { api:: create_grpc_channel, tty:: Output } ,
3228} ;
3329
3430use super :: {
3531 preview_import_config,
36- utils:: { gzip_file , validate_time_format} ,
32+ utils:: { upload_gzipped_file , validate_time_format} ,
3733 wait_for_job_completion,
3834} ;
3935
@@ -75,29 +71,10 @@ pub async fn run(ctx: Context, args: ImportCsvArgs) -> Result<ExitCode> {
7571 . into_inner ( ) ;
7672
7773 csv_file. rewind ( ) ?;
78- let compressed_data = gzip_file ( csv_file) ?;
79-
80- let rest_client = create_rest_client ( & ctx) ?;
81- let res = rest_client
82- . post ( upload_url)
83- . header ( CONTENT_ENCODING , "gzip" )
84- . header ( CONTENT_TYPE , "text/csv" )
85- . body ( compressed_data)
86- . send ( )
74+ let job_id = upload_gzipped_file ( & ctx, & upload_url, csv_file, "text/csv" )
8775 . await
8876 . context ( "failed to upload CSV file" ) ?;
8977
90- if !res. status ( ) . is_success ( ) {
91- let status = res. status ( ) ;
92- let text = res
93- . text ( )
94- . await
95- . unwrap_or_else ( |_| "<failed to read body>" . into ( ) ) ;
96- return Err ( anyhow ! (
97- "failed to upload CSV with http status {status}: {text}"
98- ) ) ;
99- }
100-
10178 let location = args. run . as_ref ( ) . map_or_else (
10279 || format ! ( "asset '{}'" , args. asset. cyan( ) ) ,
10380 |r| format ! ( "run '{}'" , r. clone( ) . cyan( ) ) ,
@@ -113,7 +90,7 @@ pub async fn run(ctx: Context, args: ImportCsvArgs) -> Result<ExitCode> {
11390
11491 return Ok ( ExitCode :: SUCCESS ) ;
11592 }
116- wait_for_job_completion ( grpc_channel, location) . await
93+ wait_for_job_completion ( grpc_channel, job_id , location) . await
11794}
11895
11996fn create_data_import_request < R : io:: Read > (
@@ -300,14 +277,14 @@ fn create_data_import_request<R: io::Read>(
300277 let mut enum_configs = Vec :: new ( ) ;
301278 let mut bit_field_configs = Vec :: new ( ) ;
302279
303- if data_type == ChannelDataType :: Enum . into ( ) {
280+ if data_type == i32 :: from ( ChannelDataType :: Enum ) {
304281 let Some ( configs) = enum_configs_iter. next ( ) else {
305282 return Err ( anyhow ! (
306283 "'{name}' was declared as type enum but --enum-config was not specified"
307284 ) ) ;
308285 } ;
309286 enum_configs = configs;
310- } else if data_type == ChannelDataType :: BitField . into ( ) {
287+ } else if data_type == i32 :: from ( ChannelDataType :: BitField ) {
311288 let Some ( configs) = bit_field_configs_iter. next ( ) else {
312289 return Err ( anyhow ! (
313290 "'{name}' was declared as type bit-field but --bit-field-config was not specified"
0 commit comments