##// END OF EJS Templates
Use tripcode from settings when fetching posts from sources
neko259 -
r1973:399be5a4 default
parent child Browse files
Show More
@@ -28,7 +28,7 b' from boards.models.attachment import Sti'
28 from boards.models.attachment.downloaders import download, REGEX_MAGNET
28 from boards.models.attachment.downloaders import download, REGEX_MAGNET
29 from boards.models.post import TITLE_MAX_LENGTH
29 from boards.models.post import TITLE_MAX_LENGTH
30 from boards.utils import validate_file_size, get_file_mimetype, \
30 from boards.utils import validate_file_size, get_file_mimetype, \
31 FILE_EXTENSION_DELIMITER
31 FILE_EXTENSION_DELIMITER, get_tripcode_from_text
32 from boards.models.attachment.viewers import FILE_TYPES_IMAGE
32 from boards.models.attachment.viewers import FILE_TYPES_IMAGE
33 from neboard import settings
33 from neboard import settings
34
34
@@ -286,8 +286,7 b' class PostForm(NeboardForm):'
286 def get_tripcode(self):
286 def get_tripcode(self):
287 title = self.cleaned_data['title']
287 title = self.cleaned_data['title']
288 if title is not None and TRIPCODE_DELIM in title:
288 if title is not None and TRIPCODE_DELIM in title:
289 code = title.split(TRIPCODE_DELIM, maxsplit=1)[1] + neboard.settings.SECRET_KEY
289 tripcode = get_tripcode_from_text(title.split(TRIPCODE_DELIM, maxsplit=1)[1])
290 tripcode = hashlib.md5(code.encode()).hexdigest()
291 else:
290 else:
292 tripcode = ''
291 tripcode = ''
293 return tripcode
292 return tripcode
@@ -9,8 +9,11 b' from django.db import models, transactio'
9 from django.utils.dateparse import parse_datetime
9 from django.utils.dateparse import parse_datetime
10 from django.utils.timezone import utc
10 from django.utils.timezone import utc
11 from django.utils import timezone
11 from django.utils import timezone
12
12 from boards.models import Post
13 from boards.models import Post
13 from boards.models.post import TITLE_MAX_LENGTH
14 from boards.models.post import TITLE_MAX_LENGTH
15 from boards.utils import get_tripcode_from_text
16 from boards import settings
14
17
15
18
16 SOURCE_TYPE_MAX_LENGTH = 100
19 SOURCE_TYPE_MAX_LENGTH = 100
@@ -42,6 +45,8 b' class ThreadSource(models.Model):'
42 if self.thread.is_archived():
45 if self.thread.is_archived():
43 logger.error('The thread {} is archived, please try another one'.format(self.thread))
46 logger.error('The thread {} is archived, please try another one'.format(self.thread))
44 else:
47 else:
48 tripcode = get_tripcode_from_text(
49 settings.get('External', 'SourceFetcherTripcode'))
45 start_timestamp = self.timestamp
50 start_timestamp = self.timestamp
46 last_timestamp = start_timestamp
51 last_timestamp = start_timestamp
47 logger.info('Start timestamp is {}'.format(start_timestamp))
52 logger.info('Start timestamp is {}'.format(start_timestamp))
@@ -59,7 +64,8 b' class ThreadSource(models.Model):'
59 if timestamp > last_timestamp:
64 if timestamp > last_timestamp:
60 last_timestamp = timestamp
65 last_timestamp = timestamp
61 if timestamp > start_timestamp:
66 if timestamp > start_timestamp:
62 Post.objects.create_post(title=title, text=item.description, thread=self.thread, file_urls=[item.link])
67 Post.objects.create_post(title=title, text=item.description,
68 thread=self.thread, file_urls=[item.link], tripcode=tripcode)
63 logger.info('Fetched item {} from {} into thread {}'.format(
69 logger.info('Fetched item {} from {} into thread {}'.format(
64 title, self.name, self.thread))
70 title, self.name, self.thread))
65 logger.info('New timestamp is {}'.format(last_timestamp))
71 logger.info('New timestamp is {}'.format(last_timestamp))
@@ -15,6 +15,7 b' from django.utils import timezone'
15 from django.utils.translation import ugettext_lazy as _
15 from django.utils.translation import ugettext_lazy as _
16
16
17 import boards
17 import boards
18 from neboard import settings
18 from boards.abstracts.constants import FILE_DIRECTORY
19 from boards.abstracts.constants import FILE_DIRECTORY
19 from boards.settings import get_bool
20 from boards.settings import get_bool
20
21
@@ -141,3 +142,11 b' def get_domain(url: str) -> str:'
141
142
142 return full_domain
143 return full_domain
143
144
145
146 def get_tripcode_from_text(text: str) -> str:
147 tripcode = ''
148 if text:
149 code = text + settings.SECRET_KEY
150 tripcode = hashlib.md5(code.encode()).hexdigest()
151 return tripcode
152
General Comments 0
You need to be logged in to leave comments. Login now