vue-tweet-pure
Version:
A Vue 3 component for embedding tweets in your Vue.js applications.
56 lines (55 loc) • 2 kB
JavaScript
var _ = Object.defineProperty;
var w = (t, s, e) => s in t ? _(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
var r = (t, s, e) => w(t, typeof s != "symbol" ? s + "" : s, e);
const f = "https://cdn.syndication.twimg.com";
class c extends Error {
constructor({ message: e, status: n, data: a }) {
super(e);
r(this, "status");
r(this, "data");
this.name = "TwitterApiError", this.status = n, this.data = a;
}
}
const u = /^[0-9]+$/;
function d(t) {
return (Number(t) / 1e15 * Math.PI).toString(6 ** 2).replace(/(0+|\.)/g, "");
}
async function l(t, s) {
var i;
if (t.length > 40 || !u.test(t))
throw new Error(`Invalid tweet id: ${t}`);
const e = new URL(`${f}/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), o = ((i = n.headers.get("content-type")) == null ? void 0 : i.includes("application/json")) ? await n.json() : void 0;
if (n.ok)
return (o == null ? void 0 : o.__typename) === "TweetTombstone" ? { tombstone: !0 } : { data: o };
if (n.status === 404)
return { notFound: !0 };
throw new c({
message: typeof o.error == "string" ? o.error : `Failed to fetch tweet at "${e}" with "${n.status}".`,
status: n.status,
data: o
});
}
export {
c as T,
l as f
};