##// 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 28 from boards.models.attachment.downloaders import download, REGEX_MAGNET
29 29 from boards.models.post import TITLE_MAX_LENGTH
30 30 from boards.utils import validate_file_size, get_file_mimetype, \
31 FILE_EXTENSION_DELIMITER
31 FILE_EXTENSION_DELIMITER, get_tripcode_from_text
32 32 from boards.models.attachment.viewers import FILE_TYPES_IMAGE
33 33 from neboard import settings
34 34
@@ -286,8 +286,7 b' class PostForm(NeboardForm):'
286 286 def get_tripcode(self):
287 287 title = self.cleaned_data['title']
288 288 if title is not None and TRIPCODE_DELIM in title:
289 code = title.split(TRIPCODE_DELIM, maxsplit=1)[1] + neboard.settings.SECRET_KEY
290 tripcode = hashlib.md5(code.encode()).hexdigest()
289 tripcode = get_tripcode_from_text(title.split(TRIPCODE_DELIM, maxsplit=1)[1])
291 290 else:
292 291 tripcode = ''
293 292 return tripcode
@@ -9,8 +9,11 b' from django.db import models, transactio'
9 9 from django.utils.dateparse import parse_datetime
10 10 from django.utils.timezone import utc
11 11 from django.utils import timezone
12
12 13 from boards.models import Post
13 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 19 SOURCE_TYPE_MAX_LENGTH = 100
@@ -42,6 +45,8 b' class ThreadSource(models.Model):'
42 45 if self.thread.is_archived():
43 46 logger.error('The thread {} is archived, please try another one'.format(self.thread))
44 47 else:
48 tripcode = get_tripcode_from_text(
49 settings.get('External', 'SourceFetcherTripcode'))
45 50 start_timestamp = self.timestamp
46 51 last_timestamp = start_timestamp
47 52 logger.info('Start timestamp is {}'.format(start_timestamp))
@@ -59,7 +64,8 b' class ThreadSource(models.Model):'
59 64 if timestamp > last_timestamp:
60 65 last_timestamp = timestamp
61 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 69 logger.info('Fetched item {} from {} into thread {}'.format(
64 70 title, self.name, self.thread))
65 71 logger.info('New timestamp is {}'.format(last_timestamp))
@@ -15,6 +15,7 b' from django.utils import timezone'
15 15 from django.utils.translation import ugettext_lazy as _
16 16
17 17 import boards
18 from neboard import settings
18 19 from boards.abstracts.constants import FILE_DIRECTORY
19 20 from boards.settings import get_bool
20 21
@@ -141,3 +142,11 b' def get_domain(url: str) -> str:'
141 142
142 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