IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   Programlama (https://www.ircforumlari.net/programlama/)
-   -   React Native / Expo Asset Downloader (https://www.ircforumlari.net/programlama/1041583-react-native-expo-asset-downloader.html)

SuLh 09 Ağustos 2024 15:45

React Native / Expo Asset Downloader
 
React Native Expo için uygulama açılışında asset indirme sistemi yapmıştım kendim için daha önce.

Kod:

import * as FileSystem from 'expo-file-system';
export class AssetsDownloader
{

    /**
    * expo construactor
    * @[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]m {*} u -> url
    * @[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]m {*} n -> name
    */
    downloadResumable = (u, n) => {
        return FileSystem.createDownloadResumable(
            u,
            this.dir + n,
            {},
            this.callback
          );
    }

    /**
    *
    * @[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]m {*} downloadProgress -> from downloadResumable
    */
    callback = downloadProgress => {
        const progress = downloadProgress.totalBytesWritten / downloadProgress.totalByte***pectedToWrite;
        return progress;
    }

    /**
    *
    * @[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]m {*} fn -> Function that fetch the asset list
    */
    constructor(fn) {
        this.fn = fn;
        this.assets = [];
        this.dir = FileSystem.documentDirectory + "assets/";
    }
    /**
    *
    * @[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]m {*} k -> Key name // ex: data.image (key: image)
    *  @[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]m {*} b -> BASE_API_URL
    */
    getFiles = async(k, b) => {
        let res = await this.fn();
        if (res.data?.length == 0 || res.data == undefined) this.assets = [];
        const { data } = res;
        data.forEach((item) => {
            this.assets.push({
                url: item[k] != null ? `${b}${item[k]}`: null,
                name: item[k]
            });
        })
        return this.assets;
    }
 
   
    downloadAssets = async(assets) => {
        let dir = await FileSystem.getInfoAsync(this.dir);
        if (!dir.exists) await FileSystem.makeDirectoryAsync(this.dir, { intermediates: true });
        assets.forEach(async(item) => {
            var info = await FileSystem.getInfoAsync(this.dir + item.name)
            if (info.exists) return console.log(`Assets ${item.name} already downloaded!`)
            this.downloadResumable(item.url, item.name).downloadAsync().then(({ uri }) => {
                console.log(`Assets ${item.name} downloaded!`)
            })
        })
    }

}

Kullanımı:

Kod:

let url = "https://blabla.com/api/getImages/";
const getImages = async() => {
    let res = await axios.get(url);
}

const assetDownloader = new AssetsDownloader(getImages);
assetDownloader.getFiles("name", url).then((res) => {
  var filteredAssets = res.filter(x => x.name != null);
  assetDownloader.downloadAssets(filteredAssets);
})


Forbidden 16 Ağustos 2024 01:01

Cevap: React Native / Expo Asset Downloader
 
Emeğine sağlık usta

Mylife 05 Nisan 2025 09:26

Cevap: React Native / Expo Asset Downloader
 
Paylaşım için teşekkürler @[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...] eline sağlık.


Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 15:46.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2025 IRCForumlari.Net Sparhawk