{"id":16220363,"url":"https://github.com/kosso/nappdownloadmanager-mod","last_synced_at":"2025-03-19T11:30:56.106Z","repository":{"id":138912833,"uuid":"84719996","full_name":"kosso/NappDownloadManager-mod","owner":"kosso","description":"Download Manager for Appcelerator Titanium (modified)","archived":false,"fork":false,"pushed_at":"2018-02-28T06:59:02.000Z","size":3067,"stargazers_count":10,"open_issues_count":3,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T18:23:11.843Z","etag":null,"topics":["android","appcelerator-titanium","downloader","ios","module"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kosso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-12T11:21:35.000Z","updated_at":"2025-01-27T20:13:51.000Z","dependencies_parsed_at":"2024-01-17T13:12:10.224Z","dependency_job_id":"7fa18d9b-5180-4b90-9c27-2dbe01917f3f","html_url":"https://github.com/kosso/NappDownloadManager-mod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosso%2FNappDownloadManager-mod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosso%2FNappDownloadManager-mod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosso%2FNappDownloadManager-mod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosso%2FNappDownloadManager-mod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kosso","download_url":"https://codeload.github.com/kosso/NappDownloadManager-mod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243985880,"owners_count":20379220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","appcelerator-titanium","downloader","ios","module"],"created_at":"2024-10-10T11:58:31.523Z","updated_at":"2025-03-19T11:30:55.133Z","avatar_url":"https://github.com/kosso.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Napp Download Manager (mod 3.0)\n\n\n[![License](http://img.shields.io/badge/license-MIT-orange.svg)](http://mit-license.org)\n\n## Description\n\nThis is a download module for Appcelerator Titanium that allows you to add urls and download the files in the background.\n\n------\n\n\n\n#### FORK UPDATE (Version 3.0 - Modified by Kosso)\n\nThese versions of the [original NappDownloadManager](https://github.com/viezel/NappDownloadManager) modules have been updated and modified by @kosso. \n\n*Why u no fork?* Due to recent Titanium SDK and Studio updates and changes since these modules were first built, I could not get basic forks of these modules to compile. Also Studio doesn't seem to play well with cross-platform module projects as it used to. So they have been split in to two seperate projects for iOS and Android. I have also added a missing Android jar which was required.   The module id is still `dk.napp.downloadmanager` for both iOS and Android, despite the change in project names.\n\n\n\nCompiled module zip files can be found in the `dist` folder for each platform.\n\n\n\n#### MODIFICATIONS\n\nMy usage of these modules required more control over the download queues, in particular the ability to totally 'nuke' and reset the download queue, in case of an app crash or other reason. The original version had some issues where incomplete downloads in the queue could not be safely deleted or removed. [[see issues](https://github.com/viezel/NappDownloadManager/issues)] - particulary when developing an app, since app UIDs change in the stored filepaths on each deployment (to the simulator or device). \n\nTo clean things up, a method called `cleanUp()` has been introduced to both platforms which will look for any existing queue data files, read them, then clean up any partial downloads from an aborted previous session and finally delete the queue data files again, completely resetting the queue. \n\nI recommend calling it right after instantiating the module, so a clean up can be performed at launch, after a potential crash. And also for good measure before starting a new queue.   [@kosso]\n\n\n\n**Note**: I also call the `stopDownloader()` method immediately after loading the module, after discovering that the module contains a 'heartbeat' which will run constantly in the background unless you stop it.\n\nI then call `restartDownloader()` just before I add download requests with `addDownload(url)` which trigger downloading. \n\n\n\n--------\n\n\n\n## Quick Start \n\n### Get it \nDownload the latest distribution ZIP-file and consult the [Titanium Documentation](http://docs.appcelerator.com/titanium/latest/#!/guide/Using_a_Module) on how install it.\n\n## Accessing the module\n\nTo access this module from JavaScript, you would do the following:\n\n```javascript\n\tvar NappDownloadManager = require(\"dk.napp.downloadmanager\");\n```\n\nThe downloader variable is a reference to the Module object.\t\n\n## Reference\n\n### Network Types Constants\n\n```javascript\n\tNappDownloadManager.NETWORK_TYPE_WIFI\n\tNappDownloadManager.NETWORK_TYPE_MOBILE\n\tNappDownloadManager.NETWORK_TYPE_ANY\n```\n\n### Priority Constants\n\n```javascript\n\tNappDownloadManager.DOWNLOAD_PRIORITY_LOW\n\tNappDownloadManager.DOWNLOAD_PRIORITY_NORMAL\n\tNappDownloadManager.DOWNLOAD_PRIORITY_HIGH\n```\n\n### Events\n\n```javascript\n\tNappDownloadManager.addEventListener('progress', handleEvent);\n\tNappDownloadManager.addEventListener('overallprogress', handleEvent);\n\tNappDownloadManager.addEventListener('paused', handleEvent);\n\tNappDownloadManager.addEventListener('failed', handleEvent);\n\tNappDownloadManager.addEventListener('completed', handleEvent);\n\tNappDownloadManager.addEventListener('cancelled', handleEvent);\t\n\tNappDownloadManager.addEventListener('started', handleEvent);\n\n```\n\nAll events send an object of the download information. Example of event handler\n\n```javascript\t\n\tfunction handleEvent(e) {\n\t\te.name;\n\t\te.url;\n\t\te.downloadedBytes;\n\t\te.totalBytes;\n\t\te.filePath;\n\t\te.createdDate;\n\t\te.priority;\n\t}\n```\n\n### maximumSimultaneousDownloads\n\n```javascript\n\tNappDownloadManager.maximumSimultaneousDownloads = 4;\n\tvar maxDownloads = NappDownloadManager.getMaximumSimultaneousDownloads();\n\tNappDownloadManager.setMaximumSimultaneousDownloads(4);\n```\n\n### permittedNetworkTypes\n```javascript\n\tNappDownloadManager.permittedNetworkTypes = NappDownloadManager.NETWORK_TYPE_ANY;\n\tvar maxDownloads = NappDownloadManager.getPermittedNetworkTypes();\n\tNappDownloadManager.setPermittedNetworkTypes(NappDownloadManager.NETWORK_TYPE_WIFI);\n```\n\n### addDownload\n\n```javascript\nNappDownloadManager.addDownload({\n\tname:'Some name',\n\turl:'http://host/file',\n\tfilePath: 'native file path',\n\tpriority: NappDownloadManager.DOWNLOAD_PRIORITY_NORMAL\n});\n```\n\n\u003e **Important**\n\u003e\n\u003e The downloader starts immediately downloading the files, after you add them! Be sure to set any event listeners before adding your first file or it might not get called!\n\n\n​\t\n### cleanUp  \n\n```javascript\n\tNappDownloadManager.cleanUp();\n```\n\n### stopDownloader\n\n```javascript\n\tNappDownloadManager.stopDownloader();\n```\n\n### restartDownloader\n\n```javascript\n\tNappDownloadManager.restartDownloader();\n```\n\n### pauseAll\n\n```javascript\n\tNappDownloadManager.pauseAll();\n```\n\n### pauseItem\n\n```javascript\n\tNappDownloadManager.pauseItem('http://host/file');\n```\n\n### resumeAll\n\n```javascript\n\tNappDownloadManager.resumeAll();\n```\n\n### resumeItem\n\n```javascript\n\tNappDownloadManager.resumeItem('http://host/file');\n```\n\n### cancelItem\n\n```javascript\n\tNappDownloadManager.cancelItem('http://host/file');\n```\n\n### deleteItem\n\n```javascript\n\tNappDownloadManager.deleteItem('http://host/file');\n```\n\n### getDownloadInfo\n\n```javascript\n\tNappDownloadManager.getDownloadInfo('http://host/file');\n```\n\n### getAllDownloadInfo\n\n```javascript\n\tNappDownloadManager.getAllDownloadInfo();\n```\n\n\n## Usage\n\nNappDownloadManager is a singleton - so only require it once globally. A good place to do so would be in alloy.js or app.js for vanilla Titanium projects. \n\n```javascript\n// if Alloy\nAlloy.Globals.NappDownloadManager = require('dk.napp.downloadmanager');\n...\n```\n\n```javascript\n// if vanilla Titanium\nvar NappDownloadManager = require('dk.napp.downloadmanager');\n\nNappDownloadManager.permittedNetworkTypes = NappDownloadManager.NETWORK_TYPE_ANY;\nNappDownloadManager.maximumSimultaneousDownloads = 4;\n\n// add events before starting the downloads\nNappDownloadManager.addEventListener('progress', function(e) {\n\t// show it somewhere\n\tvar progress=e.downloadedBytes*100.0/e.totalBytes;\n\tvar text=e.downloadedBytes+'/'+e.totalBytes+' '+Math.round(progress)+'% '+e.bps+' bps';\n});\n\nNappDownloadManager.addEventListener('completed', function(e) {\n\t// do stuff\n});\n\n// define a path where the downloaded file should be stored once complete\nvar file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'myfile.ext');\n\n// add a download\nNappDownloadManager.addDownload({\n\tname: 'myfile ..',\n\turl: \"https://example.com/myfile.ext\",\n\tfilePath: file.nativePath,\n\tpriority: NappDownloadManager.DOWNLOAD_PRIORITY_NORMAL\n});\n\n// Optionally add headers to download request\nNappDownloadManager.addDownload({\n\tname: 'myfile ..',\n\turl: \"https://example.com/myfile.ext\",\n\tfilePath: file.nativePath,\n\tpriority: NappDownloadManager.DOWNLOAD_PRIORITY_NORMAL,\n\theaders: {\"Authorization\": \"Bearer \" + Ti.App.Properties.getString(\"authToken\"), \n        \"CustomHeader\": \"CustomHeaderValue\"}\n});\n```\n\n## Changelog\n* v3.0 MOD [@kosso]\n  * Modified version supporting the latest Appcelerator Studio build tooling and SDK 6.0.1.GA\n  * Added `cleanUp()` method.  \n  * Bumped version too far for some reason.\n* v1.1.7\n  * Contains fixes if server is using Transfer-Encoding: chunked or if server doesn't send content-length header with response.\n  * Added abiility pass headers to download request (for Authorization etc).\n* v1.1.5 (iOS only)  \n  * Making sure we dont violate the Apple rule: 2.23 - Apps must follow the iOS Data Storage Guidelines or they will be rejected. We set the `NSURLIsExcludedFromBackupKey` flag. \n* v1.1.4\n  * Bugfix for invalid urls\n* v1.1.3 \n  * Added `overallprogress` event. \n  * Added failed event on connection timeouts and error.\n* v1.1.2 \n  * Bugfix. Better handling of invalid for forbidden download links. \n* v1.1.1\n  * Improvement. Better handling of Progress Event. Now it fires twice every second, instead of all the time. This limits the UI thread, if you update UI to show download progress.\n* v1.1.0 (iOS)\n  * Added 64bit support\n* v1.0.0\n  * init\n\n\n## Author\n\n**Mads Møller**  \nweb: http://www.napp.dk  \nemail: mm@napp.dk  \ntwitter: @nappdev  \n\nOriginal work by Kevin Willford\n\n## License\n\n    The MIT License (MIT)\n\n    Copyright (c) 2010-2015 Mads Møller\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n    \n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n    \n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkosso%2Fnappdownloadmanager-mod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkosso%2Fnappdownloadmanager-mod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkosso%2Fnappdownloadmanager-mod/lists"}