add publish function
This commit is contained in:
1 parent
bdf8f363e1
commit
672b5559a2
21 files changed
+268
-19
No files matched your search
@@ -8,7 +8,7 @@ export interface IWechatQRCode {
|
||||
export interface IWechatQRCodeResponse extends IWechatQRCode {}
|
||||
|
||||
export interface IWechatLoginStatusResponse {
|
||||
refresh_token: string;
|
||||
access_token: string;
|
||||
refreshToken: string;
|
||||
accessToken: string;
|
||||
user: IUser;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class ArticleService {
|
||||
return await httpClient.get(`/${this.key}/?limit=${limit}&offset=${offset}`);
|
||||
}
|
||||
|
||||
async get(id: string | string[]): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
async get(id: string): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
return httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ class ArticleService {
|
||||
return httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
async update(id: string | string[], data: IArticle): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
async update(id: string, data: IArticle): Promise<AxiosResponse<IArticleDetailResponse>> {
|
||||
return httpClient.put(`/${this.key}/${id}`, data);
|
||||
}
|
||||
|
||||
async delete(id: string | string[]): Promise<AxiosResponse<null>> {
|
||||
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||
return httpClient.delete(`/${this.key}/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
export const PUBLICATION_STATE_PENDING = 'pending';
|
||||
export const PUBLICATION_STATE_RUNNING = 'running';
|
||||
export const PUBLICATION_STATE_FINISHED = 'finished';
|
||||
|
||||
export const PUBLICATION_STATE_MAP: {
|
||||
[key: string]: string;
|
||||
} = {
|
||||
Pending: PUBLICATION_STATE_PENDING,
|
||||
Running: PUBLICATION_STATE_RUNNING,
|
||||
Finished: PUBLICATION_STATE_FINISHED
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import httpClient from '../../instance';
|
||||
import { IPublication, IPublicationDetailResponse, IPublicationListResponse } from './types';
|
||||
import { IPublication, IPublicationDetailResponse, IPublicationListResponse, IPublicationCreateRequest } from './types';
|
||||
|
||||
class PublicationService {
|
||||
key = 'publications';
|
||||
@@ -13,7 +13,7 @@ class PublicationService {
|
||||
return await httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async create(data: IPublication): Promise<AxiosResponse<IPublicationDetailResponse>> {
|
||||
async create(data: IPublicationCreateRequest): Promise<AxiosResponse<IPublicationDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
import { IArticle } from '../article/types';
|
||||
import { IPlatform } from '../platform/types';
|
||||
|
||||
export interface IPublication {
|
||||
id: number;
|
||||
name: string;
|
||||
state: string;
|
||||
platform: IPlatform;
|
||||
article: IArticle;
|
||||
}
|
||||
|
||||
export const CREDENTIAL_TYPE_COOKIES = 'Cookies';
|
||||
export const CREDENTIAL_TYPE_TOKEN = 'Token';
|
||||
|
||||
export interface IPublicationCreateRequest {
|
||||
article: string;
|
||||
platform: number;
|
||||
credential: string;
|
||||
state?: string;
|
||||
credentialType?: typeof CREDENTIAL_TYPE_COOKIES | typeof CREDENTIAL_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
export interface IPublicationListResponse {
|
||||
@@ -9,4 +25,4 @@ export interface IPublicationListResponse {
|
||||
results: IPublication[];
|
||||
}
|
||||
|
||||
export interface IPublicationDetailResponse extends IPublication {}
|
||||
export type IPublicationDetailResponse = IPublication;
|
||||
@@ -1,6 +1,7 @@
|
||||
import router from '@/router';
|
||||
import store from '@/store';
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import { camelizeKeys, decamelizeKeys } from 'humps';
|
||||
|
||||
const httpClient: AxiosInstance = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
@@ -12,14 +13,21 @@ const httpClient: AxiosInstance = axios.create({
|
||||
|
||||
httpClient.interceptors.request.use((config) => {
|
||||
const accessToken = store.getters.accessToken;
|
||||
console.log('accesstoken', accessToken);
|
||||
if (accessToken) {
|
||||
config.headers['Authorization'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
if (config.data) {
|
||||
config.data = decamelizeKeys(config.data);
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
httpClient.interceptors.response.use(
|
||||
(response) => {
|
||||
if (response.data && response.headers['content-type'] === 'application/json') {
|
||||
response.data = camelizeKeys(response.data);
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
|
||||
Reference in new issue
Block a user