package com.guo.learningprogresstracker.controller; import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.utils.TitleFetcher; import io.swagger.v3.oas.annotations.Operation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.Map; @RestController @RequestMapping("/utils") public class UtilsController { @GetMapping("/fetch-title") @Operation(summary = "获取指定URL的页面标题") public CommonResult> fetchTitle(@RequestParam String url) { if (url == null || url.isBlank()) { return CommonResult.error("url 参数不能为空"); } String title = TitleFetcher.fetchTitle(url); return CommonResult.success(Map.of("title", title != null ? title : url)); } }