| | |
| | | r.setMediaType(m.getMediaType()); |
| | | r.setTargetType(m.getTargetType()); |
| | | r.setTargetId(m.getTargetId()); |
| | | r.setThumbPath(m.getThumbPath()); |
| | | r.setDuration(m.getDuration()); |
| | | r.setDescription(m.getDescription()); |
| | | |
| | | // 追加 fullUrl(前端也可自行拼接) |
| | | if (mediaBaseUrl != null && !mediaBaseUrl.isEmpty() && m.getPath() != null) { |
| | | String base = mediaBaseUrl.endsWith("/") ? mediaBaseUrl.substring(0, mediaBaseUrl.length() - 1) : mediaBaseUrl; |
| | | String p = m.getPath().startsWith("/") ? m.getPath() : ("/" + m.getPath()); |
| | | r.setFullUrl(base + p); |
| | | } |
| | | |
| | | // 追加 fullThumbUrl |
| | | if (mediaBaseUrl != null && !mediaBaseUrl.isEmpty() && m.getThumbPath() != null) { |
| | | String base = mediaBaseUrl.endsWith("/") ? mediaBaseUrl.substring(0, mediaBaseUrl.length() - 1) : mediaBaseUrl; |
| | | String p = m.getThumbPath().startsWith("/") ? m.getThumbPath() : ("/" + m.getThumbPath()); |
| | | r.setFullThumbUrl(base + p); |
| | | } |
| | | |
| | | return r; |
| | | } |
| | | |
| | |
| | | System.out.println("输入参数: " + input); |
| | | System.out.println("targetType: " + input.getTargetType()); |
| | | System.out.println("targetId: " + input.getTargetId()); |
| | | System.out.println("thumbPath: " + input.getThumbPath()); |
| | | |
| | | try { |
| | | Media result = mediaService.saveMedia( |
| | | input.getName(), |
| | | input.getPath(), |
| | | input.getFileSize(), |
| | | input.getFileExt(), |
| | | input.getMediaType(), |
| | | input.getTargetType(), |
| | | input.getTargetId() |
| | | ); |
| | | System.out.println("保存成功,媒体ID: " + result.getId()); |
| | | Media result; |
| | | |
| | | // 如果有缩略图路径,使用支持缩略图的方法 |
| | | if (input.getThumbPath() != null && !input.getThumbPath().trim().isEmpty()) { |
| | | result = mediaService.saveMedia( |
| | | input.getName(), |
| | | input.getPath(), |
| | | input.getFileSize(), |
| | | input.getFileExt(), |
| | | input.getMediaType(), |
| | | input.getTargetType(), |
| | | input.getTargetId(), |
| | | input.getThumbPath() |
| | | ); |
| | | System.out.println("保存成功(含缩略图),媒体ID: " + result.getId()); |
| | | } else { |
| | | result = mediaService.saveMedia( |
| | | input.getName(), |
| | | input.getPath(), |
| | | input.getFileSize(), |
| | | input.getFileExt(), |
| | | input.getMediaType(), |
| | | input.getTargetType(), |
| | | input.getTargetId() |
| | | ); |
| | | System.out.println("保存成功,媒体ID: " + result.getId()); |
| | | } |
| | | |
| | | return result; |
| | | } catch (Exception e) { |
| | | System.err.println("保存媒体失败: " + e.getMessage()); |