Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #92 from codl/archive-warn
Browse files Browse the repository at this point in the history
warn when archive looks too big
  • Loading branch information
codl authored Oct 6, 2018
2 parents bbcbbff + 5278167 commit 4147673
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -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

Released 2018-07-06
Expand Down
14 changes: 14 additions & 0 deletions assets/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Banner from '../components/Banner.html';
import ArchiveForm from '../components/ArchiveForm.html';

(function settings_init(){
if(!('fetch' in window)){
Expand Down Expand Up @@ -188,4 +189,17 @@ import Banner from '../components/Banner.html';
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,
},
})
}
})();
10 changes: 10 additions & 0 deletions assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ img.avatar.mastodon {
padding-top: .6rem;
padding-bottom: .6rem;
margin-bottom: 1rem;
padding-left: 1rem;
padding-right: 1rem;
}

.banner p {
margin: .3rem 0;
}

.banner p ~ p {
margin-top: 1.3rem;
}

body > section > .banner,
Expand Down
49 changes: 49 additions & 0 deletions components/ArchiveForm.html
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def task_rollup():
file_dep=list(chain(
# fuck it
glob('assets/*.js'),
glob('components/*.html'))),
glob('components/*.html'))) + ['rollup.config.js'],
targets=[dst],
clean=True,
actions=[
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
plugins: [
svelte({
include: 'components/**/*.html',
hydratable: true,
}),
]
}
6 changes: 3 additions & 3 deletions templates/logged_in.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ <h2 id="settings-title">Your expiration rules</h2>

<h2 id='tweet_archive_import'>Tweet archive import</h2>
<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
<a href="https://twitter.com/settings/account">Twitter's settings page</a>,
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#export_request">your account settings</a>,
and upload it here.
</p>

{% if tweet_archive_failed %}
<div class="banner error">The file you uploaded is not a valid tweet archive. No posts have been imported.</div>
{% 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='hidden' name='csrf-token' value='{{g.viewer.csrf_token}}'>
</form>
Expand Down

0 comments on commit 4147673

Please sign in to comment.