[ETC] Pinata Sub Marined

2023. 2. 3. 15:31ETC

서브마린은 비공개로 유지되고 공용 IPFS 네트워크에서 벗어난 콘텐츠를 업로드하는 프로세스입니다.

Pinata Submarine을 사용하면 콘텐츠를 비공개로 유지하고 지정한 기간 동안

지속되는 프로그래밍 방식으로 액세스 토큰을 생성할 수 있고,

잠수함 콘텐츠를 보려면 전용 게이트 웨이가 필요함 .

전용 게이트웨이를 통해 서브마린 콘텐츠를 볼 때 유효한 액세스 토큰을 포함해야 함.

    const getSubMarined = async () => {

        const imagePfp1Cid = 'bafkreibyoohwj4uvno3dnwbw3kpkqjgk47unod7yns7abba5ngv3vpqafm';
        const API_KEY = '서브 마린 KEY';

        // CID (컨텐츠 식별자) 조회
        const findContent = await fetch(
            'https://managed.mypinata.cloud/api/v1/content?cidContains=' + imagePfp1Cid,
            {
                method: 'GET',
                headers: {
                    'x-api-key': API_KEY,
                },
            }
        );

        const results = await findContent.json();

        const item = results.items[0];
        const { id } = item;

        const accessTokenParams = {
            // 엑세스 토큰 유효 시간
            // timeoutSeconds: 200,
            contentIds: [id],
        };

        console.log('컨텐츠 아이디 조회...', accessTokenParams);

        // 엑세스 토큰 발급
        const URL = `https://managed.mypinata.cloud/api/v1/auth/content/jwt`;
        const dataBody = accessTokenParams;
        const headers = {
            "Content-type": "application/x-www-form-urlencoded",
            'x-api-key': API_KEY,
        }

        const response = await ApiCaller.post(URL, dataBody, false, headers);
        console.log('response...', response);
    }

    useEffect(() => { getSubMarined(); }, []);

    const getAllContents = async () => {
        const API_KEY = '서브 마린 KEY';

        // 서브 마린으로 업로드 된 컨텐츠 접근
        const URL = `https://managed.mypinata.cloud/api/v1/content`;
        const dataBody = {};
        const headers = {
            "Content-type": "application/x-www-form-urlencoded",
            'x-api-key': API_KEY,
        }

        const response = await ApiCaller.get(URL, dataBody, false, headers);
        console.log('서브마린 모든 컨텐츠 리스트...', response);
    }

    useEffect(() => { getAllContents(); }, []);

 

'ETC' 카테고리의 다른 글

[ETC] Axios interceptors  (0) 2023.07.15
[ETC] EXPO를 통한 안드로이드 앱 패키징  (0) 2023.03.02
[ETC] 서버리스(Serverless)?  (0) 2022.12.07
[ETC] Debounce 와 Throttle 차이점  (0) 2022.12.06
[Homestead] 디렉토리 추가  (0) 2022.12.02