<commit_before>(function (angular) {
    'use strict';

    angular.module('ps.storage')
        .service('FileStorage', function ($q, $rootScope, StorageService) {
            var getStore = function () {
                return chrome.fileSystem;
            };

            var getCustomFileObject = function (entry) {
                return $q(function (resolve, reject) {
                    entry.file(function (file) {

                        var foobar = {
                            "file": file,
                            "entry": entry,
                            "id": chrome.fileSystem.retainEntry(entry),
                            "objectUrl": URL.createObjectURL(file)
                        };

                        resolve(foobar);
                    });
                });
            };

            var addFileToRootScope = function (file) {
                if ($rootScope.event && $rootScope.event.files == undefined) {
                    $rootScope.event.files = [];
                }

                $rootScope.event.files.push({
                    "id": file.id,
                    "name": file.file.name,
                    "url": file.objectUrl
                });
            };

            var list = [];
            const localStorageKey = "file-ids";

            this.get = function () {

                return $q(function (resolve, reject) {
                    resolve(list);
                });
            };
            this.getAllAudio = function () {
                var get = this.get;
                return $q(function (resolve, reject) {
                    get().then(function(res) {
                        var audioList = [];
                        var i;
                        for (i= 0; i < res.length; i++){
                            if(res[i].file.type.indexOf('audio') == 0){
                                audioList.push(res[i]);
                            }
                        }
                        resolve(audioList);
                    });
                });
            };
            this.getDisplayPath = function (fileEntry, callback) {
                chrome.fileSystem.getDisplayPath(fileEntry, callback);
            };

            this.open = function () {
                return $q(function (resolve, reject) {
                    chrome.fileSystem.chooseEntry({
                        type: 'openFile',
                        acceptsAllTypes: true
                    }, function (entry) {
                        getCustomFileObject(entry).then(function (file) {
                            list.push(file);
                            addFileToRootScope(file);
                            resolve(file);
                        });
                    });
                });
            };

            this.loadFromStorage = function () {
                return $q(function (resolve, reject) {
                    StorageService.getItem(localStorageKey).then(function (arr) {
                        var idList = [];
                        idList = idList.concat(arr);

                        idList.forEach(function (item, index, array) {
                            chrome.fileSystem.isRestorable(item, function (isRestorable) {
                                if (isRestorable) {
                                    chrome.fileSystem.restoreEntry(item, function (entry) {
                                        getCustomFileObject(entry).then(function (file) {
                                            list.push(file);
                                            addFileToRootScope(file);
                                        });
                                    });
                                }
                            });
                        });

                        resolve(list);
                    });
                });
            };

            this.loadFromStorage();
        });
})(angular);<commit_msg>push teil 1 fix restore soundfiles<commit_after>(function (angular) {
    'use strict';

    angular.module('ps.storage')
        .service('FileStorage', function ($q, $rootScope, StorageService) {
            var getStore = function () {
                return chrome.fileSystem;
            };

            var getCustomFileObject = function (entry) {
                return $q(function (resolve, reject) {
                    entry.file(function (file) {

                        var foobar = {
                            "file": file,
                            "entry": entry,
                            "id": chrome.fileSystem.retainEntry(entry),
                            "objectUrl": URL.createObjectURL(file)
                        };

                        resolve(foobar);
                    });
                });
            };

            var cleanFilesInRootScope = function () {
                $rootScope.event.files = [];
            };

            var addFileToRootScope = function (file) {
                if ($rootScope.event && $rootScope.event.files == undefined) {
                    $rootScope.event.files = [];
                }

                $rootScope.event.files.push({
                    "id": file.id,
                    "name": file.file.name,
                    "url": file.objectUrl
                });
            };

            var list = [];
            const localStorageKey = "file-ids";

            this.get = function () {

                return $q(function (resolve, reject) {
                    resolve(list);
                });
            };
            this.getAllAudio = function () {
                var get = this.get;
                return $q(function (resolve, reject) {
                    get().then(function (res) {
                        var audioList = [];
                        var i;
                        for (i = 0; i < res.length; i++) {
                            if (res[i].file.type.indexOf('audio') == 0) {
                                audioList.push(res[i]);
                            }
                        }
                        resolve(audioList);
                    });
                });
            };
            this.getDisplayPath = function (fileEntry, callback) {
                chrome.fileSystem.getDisplayPath(fileEntry, callback);
            };

            this.open = function () {
                return $q(function (resolve, reject) {
                    chrome.fileSystem.chooseEntry({
                        type: 'openFile',
                        acceptsAllTypes: true
                    }, function (entry) {
                        getCustomFileObject(entry).then(function (file) {
                            list.push(file);
                            addFileToRootScope(file);
                            resolve(file);
                        });
                    });
                });
            };

            this.loadFromStorage = function () {
                return $q(function (resolve, reject) {
                    StorageService.getItem(localStorageKey).then(function (arr) {
                        var idList = [];
                        idList = idList.concat(arr);
                        cleanFilesInRootScope();

                        idList.forEach(function (item, index, array) {
                            chrome.fileSystem.isRestorable(item, function (isRestorable) {
                                if (isRestorable) {
                                    chrome.fileSystem.restoreEntry(item, function (entry) {
                                        getCustomFileObject(entry).then(function (file) {
                                            list.push(file);
                                            addFileToRootScope(file);

                                            if (index == array.length - 1) {
                                                resolve(list);
                                            }
                                        });
                                    });
                                }
                            });

                            
                        });

                    });
                });
            };

            this.loadFromStorage();
        });
})(angular);
{'fraction_non_alphanumeric': 0.10048309178743961, 'fraction_numerical': 0.0007246376811594203, 'mean_word_length': 0.8248126928162186, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4919571', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1669, 'n_words': 301}