import { UploadController } from "@/controllers/UploadController";
import { createRequest } from "@/utils/request";
const token = localStorage.getItem("token");
export const request = createRequest({
  baseURL: "https://www.infish.cn/adhuaxi/v1",
  interceptors: {
    request(req: any) {
      if (!req.headers) req.headers = {};
      req.headers["authorization"] = `Bearer ${token}`;
      return req;
    },
    // response: (res: any) => {},
  },
});
export const uploader = new UploadController(request);
export const renderTitle = (title?: string) => {
  if (title) {
    if (title.length > 30) {
      return title.substring(0, 30) + "...";
    }
    return title;
  }
  return "";
};
export const renderSummary = (summary?: string) => {
  if (summary) {
    if (summary.length >= 60) {
      return summary.substring(0, 60) + "...";
    }
    return summary;
  }
  return "";
};
