vue-tweet-pure
Version:
A Vue 3 component for embedding tweets in your Vue.js applications.
2 lines (1 loc) • 1.67 kB
JavaScript
;var w=Object.defineProperty;var f=(t,s,e)=>s in t?w(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e;var o=(t,s,e)=>f(t,typeof s!="symbol"?s+"":s,e);const c="https://cdn.syndication.twimg.com";class _ extends Error{constructor({message:e,status:n,data:i}){super(e);o(this,"status");o(this,"data");this.name="TwitterApiError",this.status=n,this.data=i}}const u=/^[0-9]+$/;function d(t){return(Number(t)/1e15*Math.PI).toString(6**2).replace(/(0+|\.)/g,"")}async function h(t,s){var a;if(t.length>40||!u.test(t))throw new Error(`Invalid tweet id: ${t}`);const e=new URL(`${c}/tweet-result`);e.searchParams.set("id",t),e.searchParams.set("lang","en"),e.searchParams.set("features",["tfw_timeline_list:","tfw_follower_count_sunset:true","tfw_tweet_edit_backend:on","tfw_refsrc_session:on","tfw_fosnr_soft_interventions_enabled:on","tfw_show_birdwatch_pivots_enabled:on","tfw_show_business_verified_badge:on","tfw_duplicate_scribes_to_settings:on","tfw_use_profile_image_shape_enabled:on","tfw_show_blue_verified_badge:on","tfw_legacy_timeline_sunset:true","tfw_show_gov_verified_badge:on","tfw_show_business_affiliate_badge:on","tfw_tweet_edit_frontend:on"].join(";")),e.searchParams.set("token",d(t));const n=await fetch(e.toString(),s),r=((a=n.headers.get("content-type"))==null?void 0:a.includes("application/json"))?await n.json():void 0;if(n.ok)return(r==null?void 0:r.__typename)==="TweetTombstone"?{tombstone:!0}:{data:r};if(n.status===404)return{notFound:!0};throw new _({message:typeof r.error=="string"?r.error:`Failed to fetch tweet at "${e}" with "${n.status}".`,status:n.status,data:r})}exports.TwitterApiError=_;exports.fetchTweet=h;