shokai / semirara

deprecated. go https://scrapbox.io
16 stars 3 forks source link

URLとcontent-typeの対応表を作る #56

Closed shokai closed 8 years ago

shokai commented 8 years ago

末尾が.jpg等じゃない画像を埋め込んだりしたい。 https://avatars.githubusercontent.com/u/34204?v=3&s=20 など、拡張子がないけど画像を返すURLが増えてきている。

サーバー側に対応表を持たせる。

サーバーからアクセスできない(パスワードがかかっている等)URLをクライアントに代わりに調べてもらうのは・・無理そう?

shokai commented 8 years ago
import axios from "axios";

(async() => {
  const res = await axios.head("http://shokai.org");
  console.log(res.status);
  console.log(res.headers["content-type"]);
})();

クライアント側で実行するのはCORS的に当然無理

shokai commented 8 years ago

とりあえずimgタグとaタグ両方描画して、imgのonloadがイベントが来たらaタグを消すのはどうか? imgは最初非表示でtagを作る

shokai commented 8 years ago

spread operatorでattrsに入れたkeyを渡そうとすると <EmbedURL src="http~~~~" {...attrs} />

Warning: Element: key is not a prop. Trying to access it will result in undefined being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://fb.me/react-special-props)

shokai commented 8 years ago

とりあえず一度content-typeが判明したURLはURLのmd5-hashをkeyとしてlocalStorageに保存しておきたい。 以後それを参照する。

shokai commented 8 years ago

クライアントのimgタグでcontent-type判定してlocalStorageに保存してサーバーにsocket.ioで送ってDBに保存しておいてサーバーサイドレンダリング時に使うという実装ができたけどこれはなんかおかしい

shokai commented 8 years ago

ふつうにサーバーがcontent-typeのリスト持ってればいい

shokai commented 8 years ago

面倒だからいいや