fix: improve toutiao image uploads
This commit is contained in:
@@ -138,7 +138,7 @@ async function uploadCover(
|
||||
|
||||
if (publishType === 'publish') {
|
||||
const form = new FormData()
|
||||
form.append('upfile', blob, 'cover.png')
|
||||
form.append('upfile', blob, imageFileName(blob, 'cover'))
|
||||
const uploaded = await transport
|
||||
.fetchJson<ToutiaoUploadPictureResponse>(
|
||||
'https://mp.toutiao.com/mp/agw/article_material/photo/upload_picture',
|
||||
@@ -164,7 +164,7 @@ async function uploadCover(
|
||||
}
|
||||
|
||||
const firstForm = new FormData()
|
||||
firstForm.append('image', blob, 'cover.png')
|
||||
firstForm.append('image', blob, imageFileName(blob, 'cover'))
|
||||
const first = await transport
|
||||
.fetchJson<ToutiaoSpiceImageResponse>(
|
||||
'https://mp.toutiao.com/spice/image?device_platform=web',
|
||||
@@ -220,7 +220,7 @@ async function uploadContentImage(
|
||||
}
|
||||
|
||||
const form = new FormData()
|
||||
form.append('image', blob, 'image.png')
|
||||
form.append('image', blob, imageFileName(blob, 'image'))
|
||||
const uploaded = await transport
|
||||
.fetchJson<ToutiaoSpiceImageResponse>(
|
||||
'https://mp.toutiao.com/spice/image?device_platform=web',
|
||||
@@ -234,6 +234,14 @@ async function uploadContentImage(
|
||||
return uploaded?.data?.image_url ?? null
|
||||
}
|
||||
|
||||
function imageFileName(blob: Blob, baseName: string): string {
|
||||
const type = blob.type.toLowerCase()
|
||||
if (type === 'image/jpeg' || type === 'image/jpg') {
|
||||
return `${baseName}.jpg`
|
||||
}
|
||||
return `${baseName}.png`
|
||||
}
|
||||
|
||||
export async function publishToutiaoArticle(
|
||||
input: ToutiaoPublishArticleInput,
|
||||
transport: ToutiaoPublishTransport,
|
||||
|
||||
Reference in New Issue
Block a user