translateMon, 27 Feb 2023

public async edit({ id, ip, userId, isMobile }: EditParams): Promise<never | string> { const user = await this.getUser(userId); user.assert(UserTypes.Permission.WriteArticle); const post = await this.postRepository.getOrFail(id); const html = post.content.body ? this.htmlUnboxing(post.content.body, isMobile) : ''; const materialId = isMobile ? `M${id}` : id; const callbackUrl = `${VERSTKA_CALLBACK_URL}/${id}`; const callbackSign = createHash('md5') .update(`${VERSTKA_SECRET}${VERSTKA_API_KEY}${materialId}${userId}${callbackUrl}`) .digest('hex'); const customFields = { mobile: isMobile, 'fonts.css': VERSTKA_FONTS, }; try { const data = new URLSearchParams(); data.append('material_id', materialId); data.append('user_id', userId); data.append('html_body', html); data.append('api-key', VERSTKA_API_KEY); data.append('callback_url', callbackUrl); data.append('host_name', VERSTKA_HOST_NAME); data.append('user_ip', ip); data.append('callback_sign', callbackSign); data.append('custom_fields', JSON.stringify(customFields)); const response = await axios(`${VERSTKA_API_URL}/open`, { data, method: 'post', }); const verstkaRespose = response.data as EditResponse; assert.ok(typeof verstkaRespose !== 'string', verstkaRespose as string); return verstkaRespose.data.edit_url; } catch (error: unknown) { this.logAxiosError(error as AxiosError); throw error; } }

def add(a, b) return a + b end

Questions about programming?Chat with your personal AI assistant