Merge pull request #92 from codl/archive-warn

warn when archive looks too big
This commit is contained in:
codl 2018-10-06 02:18:12 +02:00 committed by GitHub
commit 4147673915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 4 deletions

View File

@ -1,3 +1,7 @@
## v1.4.0
* added warning when it looks like an archive is a full "Your Twitter data" archive
## v1.3.0 ## v1.3.0
Released 2018-07-06 Released 2018-07-06

View File

@ -1,4 +1,5 @@
import Banner from '../components/Banner.html'; import Banner from '../components/Banner.html';
import ArchiveForm from '../components/ArchiveForm.html';
(function settings_init(){ (function settings_init(){
if(!('fetch' in window)){ if(!('fetch' in window)){
@ -188,4 +189,17 @@ import Banner from '../components/Banner.html';
reason_banner.parentElement.removeChild(reason_banner); reason_banner.parentElement.removeChild(reason_banner);
}) })
} }
let archive_form_el = document.querySelector('#archive-form');
if(archive_form_el){
let csrf_token = archive_form_el.querySelector('input[name=csrf-token]').value;
let archive_form = new ArchiveForm({
target: archive_form_el,
hydrate: true,
data: {
action: archive_form_el.action,
csrf_token: csrf_token,
},
})
}
})(); })();

View File

@ -76,6 +76,16 @@ img.avatar.mastodon {
padding-top: .6rem; padding-top: .6rem;
padding-bottom: .6rem; padding-bottom: .6rem;
margin-bottom: 1rem; margin-bottom: 1rem;
padding-left: 1rem;
padding-right: 1rem;
}
.banner p {
margin: .3rem 0;
}
.banner p ~ p {
margin-top: 1.3rem;
} }
body > section > .banner, body > section > .banner,

View File

@ -0,0 +1,49 @@
<form action={action} method='post' enctype='multipart/form-data'>
{#if file_too_big}
<div class="banner warning">
<p>The file you have selected is very large.</p>
<p>Twitter has two types of archives, <b>Forget does not support
"Your Twitter data" archives, only "Tweet archives"</b>
available from
<a href="https://twitter.com/settings/account#export_request">your account settings</a>.
Please make sure you have the right type of archive.</p>
</div>
{/if}
<input type="file" name="file" accept="application/zip,.zip"
on:change="take_file(this.files)">
<input type="submit" value="Upload">
<input type='hidden' name='csrf-token' value={csrf_token}>
</form>
<script>
function get_file_size(file_list){
/* returns size of selected file given an <input type="file">
or 0 if no file is selected */
let size = 0;
for(let i = 0; i < file_list.length; i++){
size += file_list[i].size;
}
return size;
}
export default {
data(){
return { file_size: 0 }
},
oncreate(){
},
methods: {
take_file(file_list){
this.set({file_size: get_file_size(file_list)});
},
},
computed: {
file_too_big: ({file_size}) => file_size > 10000000, // 10 MB
},
}
</script>

View File

@ -125,7 +125,7 @@ def task_rollup():
file_dep=list(chain( file_dep=list(chain(
# fuck it # fuck it
glob('assets/*.js'), glob('assets/*.js'),
glob('components/*.html'))), glob('components/*.html'))) + ['rollup.config.js'],
targets=[dst], targets=[dst],
clean=True, clean=True,
actions=[ actions=[

View File

@ -7,6 +7,7 @@ export default {
plugins: [ plugins: [
svelte({ svelte({
include: 'components/**/*.html', include: 'components/**/*.html',
hydratable: true,
}), }),
] ]
} }

View File

@ -139,8 +139,8 @@
<h2 id='tweet_archive_import'>Tweet archive import</h2> <h2 id='tweet_archive_import'>Tweet archive import</h2>
<p> <p>
Twitter's API only lets us access up to 3200 of your most recent tweets. If you have more tweets than that, you can request a zip archive of your tweets from Twitter's API only lets us access up to 3200 of your most recent tweets. If you have more tweets than that, you can request a tweet archive from
<a href="https://twitter.com/settings/account">Twitter's settings page</a>, <a href="https://twitter.com/settings/account#export_request">your account settings</a>,
and upload it here. and upload it here.
</p> </p>
@ -148,7 +148,7 @@
<div class="banner error">The file you uploaded is not a valid tweet archive. No posts have been imported.</div> <div class="banner error">The file you uploaded is not a valid tweet archive. No posts have been imported.</div>
{% endif %} {% endif %}
<form action='{{url_for('upload_tweet_archive')}}' method='post' enctype='multipart/form-data'> <form action='{{url_for('upload_tweet_archive')}}' method='post' enctype='multipart/form-data' id='archive-form'>
<input type="file" name='file' accept='application/zip,.zip'><input type="submit" value="Upload"> <input type="file" name='file' accept='application/zip,.zip'><input type="submit" value="Upload">
<input type='hidden' name='csrf-token' value='{{g.viewer.csrf_token}}'> <input type='hidden' name='csrf-token' value='{{g.viewer.csrf_token}}'>
</form> </form>