|
1 | 1 | package io.imagekit.sdk.tasks; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.databind.JavaType; |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; |
3 | 5 | import com.google.gson.Gson; |
4 | 6 | import com.google.gson.JsonElement; |
5 | 7 | import com.google.gson.JsonParser; |
|
37 | 39 | import okhttp3.*; |
38 | 40 |
|
39 | 41 | import java.io.IOException; |
| 42 | +import java.lang.reflect.Field; |
| 43 | +import java.util.Arrays; |
| 44 | +import java.util.HashMap; |
40 | 45 | import java.util.List; |
41 | 46 | import java.util.Locale; |
42 | 47 | import java.util.Map; |
@@ -114,29 +119,58 @@ public Result updateFileDetail(FileUpdateRequest fileUpdateRequest) |
114 | 119 | return result; |
115 | 120 | } |
116 | 121 |
|
117 | | - public ResultList getFileList(GetFileListRequest getFileListRequest) throws ForbiddenException, TooManyRequestsException, |
118 | | - InternalServerException, UnauthorizedException, BadRequestException, UnknownException { |
| 122 | + public ResultList getFileList(Map<String, String> options) throws ForbiddenException, TooManyRequestsException, |
| 123 | + InternalServerException, UnauthorizedException, BadRequestException, UnknownException, InstantiationException, IllegalAccessException { |
119 | 124 | ResultList resultList = new ResultList(); |
120 | 125 | Map<String, String> headers = Utils.getHeaders(imageKit); |
121 | 126 |
|
122 | | -// ObjectMap objectMapper = new ObjectMapper(); |
123 | | -// ModelMapp |
124 | 127 | QueryMaker queryMaker = new QueryMaker(); |
125 | | -// for (Map.Entry<String, String> entry : ) { |
126 | | -// queryMaker.put(String.format("%s=%s", entry.getKey(), entry.getValue())); |
| 128 | +// Map<String, String> options = new HashMap<>(); |
| 129 | +// if (getFileListRequest.getType() != null) { |
| 130 | +// options.put("type", getFileListRequest.getType()); |
| 131 | +// } |
| 132 | +// if (getFileListRequest.getSort() != null) { |
| 133 | +// options.put("sort", getFileListRequest.getSort()); |
| 134 | +// } |
| 135 | +// if (getFileListRequest.getPath() != null) { |
| 136 | +// options.put("path", getFileListRequest.getPath()); |
| 137 | +// } |
| 138 | +// if (getFileListRequest.getSearchQuery() != null) { |
| 139 | +// options.put("searchQuery", getFileListRequest.getSearchQuery()); |
| 140 | +// } |
| 141 | +// if (getFileListRequest.getFileType() != null) { |
| 142 | +// options.put("fileType", getFileListRequest.getFileType()); |
| 143 | +// } |
| 144 | +// if (getFileListRequest.getLimit() != null) { |
| 145 | +// options.put("limit", getFileListRequest.getLimit()); |
127 | 146 | // } |
| 147 | +// if (getFileListRequest.getSkip() != null) { |
| 148 | +// options.put("skip", getFileListRequest.getSkip()); |
| 149 | +// } |
| 150 | +// if (getFileListRequest.getTags() != null) { |
| 151 | +// options.put("tags", Arrays.toString(getFileListRequest.getTags())); |
| 152 | +// } |
| 153 | + System.out.println("options:==> " + options); |
| 154 | + for (Map.Entry<String, String> entry : options.entrySet()) { |
| 155 | + queryMaker.put(String.format("%s=%s", entry.getKey(), entry.getValue())); |
| 156 | + } |
| 157 | + |
| 158 | + System.out.println("queryMake:--> " + queryMaker.get()); |
128 | 159 |
|
129 | 160 | String url = String.format(Locale.US, API_BASE_URL.concat("v1/files?%s"), queryMaker.get()); |
130 | 161 |
|
| 162 | + System.out.println("url:--> " + url); |
131 | 163 | request = new Request.Builder().url(url).get().headers(Headers.of(headers)).build(); |
132 | 164 |
|
133 | 165 | try { |
134 | 166 | Response response = client.newCall(request).execute(); |
135 | 167 | String respBody = ""; |
136 | 168 | if (response.code() == 200) { |
137 | 169 | respBody = response.body().string(); |
138 | | - List<BaseFile> files = new Gson().fromJson(respBody, new TypeToken<List<BaseFile>>() { |
139 | | - }.getType()); |
| 170 | +// System.out.println("respBody:==> " + respBody); |
| 171 | + List<BaseFile> files = new Gson().fromJson(respBody, |
| 172 | + new TypeToken<List<BaseFile>>() { |
| 173 | + }.getType()); |
140 | 174 | resultList.setResults(files); |
141 | 175 | resultList.setRaw(respBody); |
142 | 176 | } else { |
|
0 commit comments